【问题标题】:"Could not find com.google.firebase:firebase-analytics"“找不到 com.google.firebase:firebase-analytics”
【发布时间】:2021-07-17 20:48:26
【问题描述】:

请我在通过添加 firebase 依赖项更改这些文件后发现运行我的应用程序的问题。非常感谢您的帮助。

我的应用程序最初可以运行,但是在将 firebase 依赖项添加到 Gradle 构建后,我得到了 构建失败异常。我已经阅读了 Stackoverflow 上提供的许多解决方案,但它们并没有解决我的问题。请在下面找到我的代码

\\I am facing an error running my application and please find both build gradles code listed below
\\This is my build gradle in my main project

buildscript {
    repositories {
        google()
        jcenter()
    }

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

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
}


\\This is my build gradle in my app

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 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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 30

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.tchow"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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 'com.google.firebase:firebase-analytics'
}


\\Error Message

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:.
     Required by:
         project : app 

【问题讨论】:

    标签: java android firebase flutter gradle


    【解决方案1】:

    您需要添加 BoM:

    dependencies {
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:26.8.0')
    
    // Declare the dependency for the Analytics library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-analytics'
    

    }

    【讨论】:

    • 我刚刚清除了我的错误,确保我使用了这个依赖类路径 'com.google.gms:google-services:4.0.1'
    猜你喜欢
    • 2021-02-25
    • 2017-02-19
    • 2016-11-12
    • 2020-07-27
    • 2018-10-15
    • 2018-11-30
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    相关资源
    最近更新 更多