找不到 com.google.firebase:firebase-crashlytics flutter。

3

我在Flutter方面经验有限,但已经做了一段时间。我的当前项目使用Firebase,因此我正在使用flutterfire包,到目前为止,它是我最可怕的噩梦。建立失败之上又建立失败。需要注意的是,iOS正常工作。最近出现了以下问题:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':firebase_crashlytics:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':firebase_crashlytics:debugCompileClasspath'.
   > Could not find com.google.firebase:firebase-crashlytics:.
     Required by:
         project :firebase_crashlytics

* 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 1s
Exception: Gradle task assembleDebug failed with exit code 1

android/build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:3.5.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:google-services:4.3.4"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.3.0"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}

subprojects {
    project.evaluationDependsOn(':app')
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
        }
    }
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core' &&
                    !details.requested.name.contains('androidx')) {
                details.useVersion "1.0.1"
            }
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

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"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'


android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
    }

    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.tendo.app"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    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
        }
    }
}

rootProject.ext {
  set('FlutterFire', [
    FirebaseSDKVersion: '21.1.0'
  ])
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    implementation platform('com.google.firebase:firebase-bom:25.12.0')
}

3个回答

2

您需要在应用级别的gradle文件app/build.gradle实现依赖项

// Add the Firebase Crashlytics SDK.
    implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
    // Recommended: Add the Google Analytics SDK.
    implementation 'com.google.firebase:firebase-analytics:18.0.0'

“dependencies”部分应该像这样:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    // Add the Firebase Crashlytics SDK.
    implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
    // Recommended: Add the Google Analytics SDK.
    implementation 'com.google.firebase:firebase-analytics:18.0.0'
}

我希望这可以解决你的问题。


我还想建议您遵循此初始化Crashlytics,以针对Java / Kotlin的特定依赖项设置。 - dipakbari4
我尝试了一下,仍然出现了相同的构建失败和相同的消息:( - Quajo Duke
我已经更新了代码。请尝试在您的代码中进行更新。希望这能够正常工作。 - dipakbari4

1
尝试在android/build.gradle中更改版本:
    classpath 'com.google.gms:google-services:4.3.3'
    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'

我希望我已经帮助了你


我已经一遍又一遍地尝试过了,你现在看到的这个版本是我从 Firebase 官方文档中得到的。我知道这个版本来自 fluttterfire 的文档。但是,我仍然尝试了你的答案,构建仍然失败了 :( - Quajo Duke

0

需要检查使用 setCrashlyticsCollectionEnabled 的情况,因为如果你禁用了崩溃收集 setCrashlyticsCollectionEnabled(false),然后如果稍后想要启用它,只是注释掉上面的那一行是不会自动开始收集过程的,如果应用程序之前已经安装了 'false' 标志,那么需要显式调用 setCrashlyticsCollectionEnabled(true) 重新启用。

但对我的问题来说,正是在 setCrashlyticsCollectionEnabled(true) 这里,我每次启动时都调用它,所以我将其注释掉,错误就消失了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接