【问题标题】:Could not find com.google.firebase:firebase-analytics-ktx:. Required by: project :app找不到 com.google.firebase:firebase-analytics-ktx:。要求:项目:app
【发布时间】:2021-02-25 12:40:37
【问题描述】:

我按照在 Firestore 中注册我的移动应用程序的步骤操作,但是当我尝试运行代码时出现以下错误。我在注册我的应用程序时从 firestore 下载了 google services.json 并将其添加到我的项目的 android/app 级别。我还在我的 android/app/build gradle 文件中添加了“com.google.firebase:firebase-analytics-ktx”

FAILURE: Build failed with an exception.

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

* 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

我的项目级构建等级如下

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

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
}
 

我的应用级构建等级如下

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.ashniz.firestore_time_compare"
        minSdkVersion 21
        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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics-ktx'
}

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

有人知道如何解决这个问题吗?谢谢

【问题讨论】:

  • 如果您想将 Firebase 分析添加到您的 Flutter 应用中,您应该按照文档中的说明进行操作。这不涉及更改 build.gradle - 为此有颤振插件。 firebase.google.com/docs/flutter/setup

标签: firebase flutter gradle firebase-analytics


【解决方案1】:

尝试替换这个dep

implementation 'com.google.firebase:firebase-analytics-ktx'

implementation 'com.google.firebase:firebase-analytics:17.5.0'

【讨论】:

    【解决方案2】:

    我只能像这样让 firebase BoM 与 build.gradle.kts 一起工作:

    implementation(platform("com.google.firebase:firebase-bom:28.4.1"))
    implementation("com.google.firebase:firebase-analytics-ktx")
    implementation("com.google.firebase:firebase-crashlytics-ktx")
    

    【讨论】:

    • 谢谢,将平台放在括号内是缺失的部分。
    • 它救了我——实现平台("com.google.firebase:firebase-bom:28.4.1")
    • 轰隆隆!这对我有用。谢谢!
    【解决方案3】:

    您可能希望开始使用材料清单,而不是依赖可能不兼容的不同 Firebase 库的特定版本,例如:

    dependencies {
      // Import the BoM for the Firebase platform
      implementation platform('com.google.firebase:firebase-bom:26.5.0')
    
      // Declare the dependencies for the desired Firebase products without specifying versions
      implementation 'com.google.firebase:firebase-analytics-ktx'
      implementation 'com.google.firebase:firebase-firestore-ktx'
    }
    

    Firebase Android BoM(物料清单)使您能够通过仅指定一个版本(即 BoM 版本)来管理所有 Firebase 库版本。

    当您在应用中使用 Firebase BoM 时,BoM 会自动提取映射到 BoM 版本的各个库版本。所有单独的库版本都将兼容。当您在应用中更新 BoM 版本时,您在应用中使用的所有 Firebase 库都将更新为映射到该 BoM 版本的版本。

    通过https://firebase.google.com/docs/android/learn-more#bom了解更多信息

    【讨论】:

      【解决方案4】:

      我遇到了类似的问题,在我的情况下,我使用的是 BoM,但我已经声明了 BoM 依赖项

      implementation 'com.google.firebase:firebase-bom:28.0.1'  // without platform
      

      而不是

      implementation platform('com.google.firebase:firebase-bom:28.0.1')
      

      【讨论】:

      • 是的,它是这样工作的!
      猜你喜欢
      • 2021-07-17
      • 2020-12-22
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-19
      • 2016-11-12
      • 2020-07-27
      相关资源
      最近更新 更多