【问题标题】:adding firebase to flutter project and getting FAILURE: Build failed with an exception error将firebase添加到flutter项目并获得FAILURE:构建失败并出现异常错误
【发布时间】:2019-11-23 10:52:00
【问题描述】:

对于 [this flutter library][1] as barcode scanner 我应该将 firebase 添加到项目中,但是在这样做之后我得到了这个错误,我还不能修复它

在调试模式下在 WAS LX1A 上启动 lib\main.dart... 正在初始化 gradle... 解决依赖关系... * 运行 Gradle 时出错:ProcessException: Process "E:\Projects\Flutter\barcode_scanner\android\gradlew.bat" exited 异常:

FAILURE:构建失败并出现异常。

  • 其中:构建文件 'E:\Projects\Flutter\barcode_scanner\android\app\build.gradle' 行: 14

  • 出了什么问题:评估项目 ':app' 时出现问题。

    ASCII

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

  • 通过https://help.gradle.org获得更多帮助

在 6 秒内构建失败命令: E:\Projects\Flutter\barcode_scanner\android\gradlew.bat app:properties

以错误结束:请检查您的 Gradle 项目设置 android/文件夹。

第 14 行是:

apply plugin: 'com.android.application'

我不确定是什么问题,这是我的实现

pabspec.yaml内容:

version: 1.0.0+1
environment:
  sdk: '>=2.0.0-dev.28.0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^0.4.0
  ...
...

android/build.gradle内容:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

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.")
}

apply plugin: '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 "barcodescanner.pishguy.barcode_scanner"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        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 {
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
}
apply plugin: 'com.google.gms.google-services'

运行flutter 命令:

E:\Projects\Flutter\barcode_scanner>flutter pub get
Running "flutter pub get" in barcode_scanner...                     2.7s


  [1]: https://github.com/facundomedica/fast_qr_reader_view

【问题讨论】:

  • 有没有人有当前的解决方案,因为 google-services 的当前版本是 4.3.2?

标签: flutter


【解决方案1】:

'com.google.gms:google-services:4.3.0' 存在问题。
将其切换到 'com.google.gms:google-services:4.2.0',它对我有用。

【讨论】:

  • 为我工作!谢谢!
  • 是的!设置: build.gradle 中的类路径 'com.google.gms:google-services:4.2.0' 有效!
【解决方案2】:

这是我同样的问题;我设法最终解决了这个问题。

这是我对代码所做的更改:

在 AppName/Android/gradle/build.gradle:

buildscript {
    ext.kotlin_version = '1.3.50' //had to changed it previously 1.2.71
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1' //had to changed previously 3.2.1
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.2'
    }
}

然后在 AppName/Android/gradle/wrapper/gradle-wrapper.properties 我刚刚更改了这一行:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip //it was peviously gradle-4.10.2-all.zip

在所有这些更改之后,我的应用程序正常工作。

【讨论】:

  • gradle-wrapper-properties 中的 Gradle 版本是什么?
  • 这对我有用 com.google.gms:google-services:4.3.3。谢谢。
【解决方案3】:

最新版本的 firebase 库中有一些 breaking changes。我遇到了同样的问题,但在migrating to AndriodX 之后一切正常。

【讨论】:

    【解决方案4】:

    如果这个 'com.google.gms:google-services:4.3.0'。 将其切换为 'com.google.gms:google-services:4.2.0' 不起作用或像我一样带来其他错误......添加此

    subprojects {
            project.configurations.all {
                resolutionStrategy.eachDependency { details ->
                    if (details.requested.group == 'com.android.support'
                            && !details.requested.name.contains('multidex') ) {
                        details.useVersion "27.1.1"
                    }
                    if (details.requested.group == 'androidx.core'
                            && !details.requested.name.contains('androidx') ) {
                        details.useVersion "1.0.1"
                    }
                }
            }
        }
    

    到 android/build.gradle

    所以你的代码将是

     buildscript {
        ext.kotlin_version = '1.2.51'
        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.2.0'
        }
    
        subprojects {
            project.configurations.all {
                resolutionStrategy.eachDependency { details ->
                    if (details.requested.group == 'com.android.support'
                            && !details.requested.name.contains('multidex') ) {
                        details.useVersion "27.1.1"
                    }
    
                    if (details.requested.group == 'androidx.core'
                            && !details.requested.name.contains('androidx') ) {
                        details.useVersion "1.0.1"
                    }
                }
            }
        }
    
    }
    
    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
    }
    

    【讨论】:

    • 请分享我遇到同样问题的问题。提前致谢
    • 按照这里的所有解决方案,如果它们不起作用,请添加我的
    猜你喜欢
    • 2019-05-24
    • 2020-06-13
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 2018-10-22
    • 2014-04-08
    相关资源
    最近更新 更多