【问题标题】:In my project it failed to add "firebase" to android studio在我的项目中,它未能将“firebase”添加到 android studio
【发布时间】:2018-08-08 08:23:50
【问题描述】:

我正在将 firebase 添加到我的项目中,如官方网站中所述。

在第四步中,它说添加compile 'com.google.firebase:firebase-core:16.0.0'

但尝试同步 gradle 时会出错:

并尝试下载它们 (install repository abd synch project) 我会收到此错误:

这是我的 gradle 依赖项:

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.google.android.gms:play-services-gcm:15.0.1'
    compile 'com.google.android.gms:play-services-location:15.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.google.firebase:firebase-auth:11.6.2'
    compile 'com.google.android.gms:play-services-auth:15.0.1'
    compile 'com.google.code.gson:gson:2.7'
    compile('io.socket:socket.io-client:1.0.0') {
        // excluding org.json which is provided by Android
        exclude group: 'org.json', module: 'json'
    }
    compile 'com.onesignal:OneSignal:3.6.5'
    compile 'com.android.volley:volley:1.0.0'
    testCompile 'junit:junit:4.12'
}

这个答案也不起作用: this

更新

我的项目级 gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:4.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        mavenCentral()
        google()
    }
}

【问题讨论】:

  • 不是答案,而是使用implementation 而不是compile
  • 您是否在 build.gradle 文件末尾添加了apply plugin: 'com.google.gms.google-services'?我在你的代码中看不到它。

标签: android firebase android-studio android-studio-3.0


【解决方案1】:

升级以下内容:

  implementation 'com.google.firebase:firebase-auth:11.6.2'

进入这个:

 implementation 'com.google.firebase:firebase-auth:16.0.2'

在顶级 gradle 文件中添加 google 服务插件版本 4.0.1google() repo:

buildscript {
// ...
dependencies {
    // ...
    classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
  }
}

allprojects {
// ...
repositories {
    // ...
    google() // Google's Maven repository
    }
 }

【讨论】:

  • 我都拥有了,请参阅我的帖子更新。我将 11.6.2 更改为 16.0.2 但再次出现相同的错误。
【解决方案2】:

使用相同版本的 firebase 服务以避免冲突。 参考https://firebase.google.com/docs/android/setup 解决您的问题。

【讨论】:

    【解决方案3】:

    在继续之前,请清理并重建您的项目。

    然后在 app/build.gradle

    添加apply plugin: 'com.google.gms.google-services' 就像下面的代码 sn-p。

    android {
      // ...
    }
    
    dependencies {
      // ...
    }
    
    // ADD THIS AT THE BOTTOM
    apply plugin: 'com.google.gms.google-services'
    

    并确保使用的所有库都为here

    希望对你有帮助!

    【讨论】:

    • 我无法清理项目:错误:无法解析配置“:app:debugCompileClasspath”的所有文件。 > 找不到 com.google.android.gms:play-services-measurement-base:11.6.2。
    • @hsbr13 你应用插件了吗?可以在问题处更新您的代码吗?
    • @hsbr13 看清楚了,在app/build.gradle,在dependencies后面添加apply插件到底部
    【解决方案4】:

    firebase-core 添加到您的依赖项块中:

    implementation 'com.google.firebase:firebase-core:16.0.1'
    

    6 月 12 日发布的Firebase SDK release notes 说明:

    您的应用 gradle 文件现在必须明确列出 com.google.firebase:firebase-core 作为 Firebase 的依赖项 服务按预期工作。

    在存储库列表中首先列出 google() 也更安全:

    repositories {
        google()
        jcenter()
        ...
    }
    

    【讨论】:

    • 您是否也更改了firebase-auth:11.6.2 以使用新版本,例如16.0.2?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-14
    • 2019-10-13
    • 2017-12-11
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    相关资源
    最近更新 更多