在我的项目中,无法向Android Studio添加“ firebase”

时间:2018-08-08 08:23:50

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

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

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

但是尝试同步gradle我会得到错误:

image

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

image

这是我的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()
    }
}

4 个答案:

答案 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()回购:

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

然后在 app / build.gradle

添加 apply plugin: 'com.google.gms.google-services' 就像下面的代码片段一样。

android {
  // ...
}

dependencies {
  // ...
}

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

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

希望有帮助!

答案 3 :(得分:0)

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