我正在尝试将Firebase集成到我现有的Flutter应用程序中。集成之前,我已将项目从Android Studio迁移到AndroidX。我已经完成了将Firebase集成到Flutter中的官方指南中提到的步骤。当我运行该应用程序时,它给了我错误:
- 运行Gradle时出错:ProcessException:进程“ E:\ My Projects \ MyProject \ android \ gradlew.bat”异常退出:
失败:构建失败,并出现异常。
其中:构建文件'E:\ My Projects \ MyProject \ android \ app \ build.gradle'行:24
出了什么问题:评估项目':app'时出现问题。
ASCII
尝试:使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获取完整的见解。
- 获得更多帮助
在8秒内建立失败命令:E:\ My Projects \ MyProject \ android \ gradlew.bat app:properties
请在android /文件夹中查看您的Gradle项目设置。
我搜索了此错误,发现了一些答案,指示从com.google.gms:google-services:4.2.0
切换到com.google.gms:google-services:4.3.2
。做到了,并得到了这个错误:
registerResGeneratingTask已弃用,请使用 registerGeneratedResFolders(FileCollection)registerResGeneratingTask 弃用,请使用registerGeneratedResFolders(FileCollection) registerResGeneratingTask已弃用,请使用 registerGeneratedResFolders(FileCollection)Gradle任务assembleDebug 失败,退出代码为1
对此进行了搜索,发现com.google.gms:google-services:4.3.0
已解决此问题。所以我在build.gradle
中使用了它,这就是我得到的:
- 运行Gradle时出错:ProcessException:进程“ E:\ My Projects \ MyProject \ android \ gradlew.bat”异常退出:
失败:构建失败,并出现异常。
其中:构建文件'E:\ My Projects \ MyProject \ android \ app \ build.gradle'行:24
出了什么问题:评估项目':app'时出现问题。
ASCII
尝试:使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获取完整的见解。
- 获得更多帮助
在5秒内失败,命令:E:\ My Projects \ MyProject \ android \ gradlew.bat app:properties
请在android /文件夹中查看您的Gradle项目设置。
似乎没有什么对我有用。请在下面找到gradle文件的内容。
android / gradle.properties:
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
android / build.gradle:
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android / app / build.gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.buy_io"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
apply plugin: 'com.google.gms.google-services'
pubspec.yaml:
name: my_app
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_money_formatter: ^0.8.3
font_awesome_flutter: ^8.5.0
firebase_core: ^0.4.0+9
firebase_auth: ^0.14.0+5
cloud_firestore: ^0.12.9+5
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
uses-material-design: true
assets:
- images/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: Muli
fonts:
- asset: fonts/Muli-ExtraLight.ttf
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages