评估项目 ':app' 时出现问题 - Firebase 与 Flutter 的集成



我正在尝试将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

  • 出现问题:评估项目":应用程序"时出现问题。

    ASCII

  • Try:使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。使用--scan运行以获得完整的见解。

  • 获取更多帮助,请访问https://help.gradle.org

BUILD FAILED in 8s Command:E:\MyProjects\MyProject\android\gradlew.bat应用程序:属性

请在android/文件夹中查看您的Gradle项目设置。

我搜索了这个错误,找到了一些指示从com.google.gms:google-services:4.3.2切换到com.google.gms:google-services:4.2.0的答案。这样做了,得到了这个错误:

registerResGeneratingTask已弃用,请使用registerGeneratedResFolders(FileCollection(registerResGeneratingTask已弃用,请使用registerGeneratedResFolders(FileCollection(registerResGeneratingTask已弃用,请使用registerGeneratedResFolders(FileCollection(渐变任务程序集调试失败,退出代码为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

  • 出现问题:评估项目":应用程序"时出现问题。

    ASCII

  • Try:使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。使用--scan运行以获得完整的见解。

  • 获取更多帮助,请访问https://help.gradle.org

BUILD FAILED in 5s Command:E:\MyProjects\MyProject\android\gradlew.bat应用程序:属性

请在android/文件夹中查看您的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

这里最好的做法是尝试删除您设置的Firebase SDK,看看Flutter项目是否构建。然后尝试使用flutterfire configure设置Firebase。有关更多详细信息,请参阅文档中的本指南。

最新更新