颤动的firebase错误“失败:构建失败并出现异常”

Posted

技术标签:

【中文标题】颤动的firebase错误“失败:构建失败并出现异常”【英文标题】:flutter firebase error "FAILURE: Build failed with an exception" 【发布时间】:2020-03-25 12:18:03 【问题描述】:

project/build.gradle

应用插件:'com.android.application'

dependencies 
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.3.2'

在 app/build.gradle 中

第 24 行应用插件:'com.android.application'

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android 
    compileSdkVersion 28

    lintOptions 
        disable 'InvalidPackage'
    

    defaultConfig 
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "blablabla.com"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.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 
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'


apply plugin: 'com.google.gms.google-services'

在 pubspec.yaml 中

dependencies:
  flutter:
    sdk: flutter
  firebase_database: ^2.0.2
  firebase_core: ^0.3.1+1
  timeago: ^2.0.10

我收到此错误

$ flutter run
Using hardware rendering with device Android SDK built for x86. If you
get graphics artifacts, consider enabling software rendering with       
"--enable-software-rendering".
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...                                             2.2s 
Resolving dependencies...                                               
* Error running Gradle:
ProcessException: Process
"C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\gradlew.bat" exited abnormally:

FAILURE: Build failed with an exception.

* Where:
Build file
'C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\app\build.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':app'.
> ASCII

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or
--debug option to get more log output. Run with --scan to get full
insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
  Command:
  C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\gradlew  .bat app:properties


Please review your Gradle project setup in the android/ folder.

如何解决这个错误...???

【问题讨论】:

我建议您将项目迁移到 AndroidX 并重试 【参考方案1】:

凹凸依赖版本:

classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.gms:google-services:4.3.3'
  firebase_database: ^3.1.0
  firebase_core: ^0.4.2+1

app/build.gradle 中添加这些:

android 
    ...

    defaultConfig 
        ...
        multiDexEnabled true // add this
    


dependencies 
    ...
    implementation 'com.android.support:multidex:1.0.3' // add this

不要忘记在 app/ 文件夹中创建 google-services.json 文件并用您的数据 (docs link) 或使用一些模拟 (如 this one) 填充它:


  "project_info": ...,
  "client": [...],

【讨论】:

以上是关于颤动的firebase错误“失败:构建失败并出现异常”的主要内容,如果未能解决你的问题,请参考以下文章

颤动的firebase错误“失败:构建失败并出现异常”

类在firebase消息颤动上找不到异常

如何在颤动中处理 Firebase Auth 未处理的异常? [复制]

升级firebase核心后颤动Ios构建失败

使用firebase时颤动的Gradle问题

未来的构建器颤动 firebase 错误:“Iterable<BlogPost>”类型的值无法分配给“List<BlogPost>”类型的变量