【问题标题】:How to use Firebase in Android?如何在 Android 中使用 Firebase?
【发布时间】:2019-07-15 16:35:13
【问题描述】:

将 Firebase 添加到我的应用后,我因 gradle 问题而生气, 我得到错误: 找不到 com.google.android.gms.internal.zzbgl 的类文件

我使用的是android location和url stringRequest,在那之前它运行良好,然后我将Firebase添加到gradle(我已经在Firebase网站上注册并添加了生成的google-services.json)

我检查了很多没有帮助的答案,我已将 gradle 更新到 3.4.2 仍然无法正常工作

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.example.mapwithmarker"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.mcxiaoke.volley:library:1.0.19'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    testImplementation 'junit:junit:4.12'
}

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


// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

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

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

有什么帮助吗?

【问题讨论】:

标签: android firebase android-gradle-plugin google-play-services


【解决方案1】:

正如official docs所提到的,

“不要使用组合播放服务目标。它引入了数十个库,使您的应用程序膨胀。相反,只需指定您的应用使用的特定 Google Play 服务 API。”

您不应使用组合播放服务库。而是尝试使用您需要的特定库并尝试将特定库更新到 17.0.0

【讨论】:

【解决方案2】:

您应该始终使用兼容版本的 firebase 和 play-services 库。版本应该同时发布。

在这种情况下

改变这一行:

implementation 'com.google.android.gms:play-services:12.0.1'

有了这个:

implementation 'com.google.android.gms:play-services:17.0.1'

【讨论】:

  • 这会产生这个错误:错误:无法解决:com.google.android.gms:play-services:17.0.1
  • 无法解析 com.google.firebase:firebase-core:17.0.0。
【解决方案3】:

使用这个Firebase documentation

或者按照这个:

工具 -> Firebase -> 选择你的库 -> 按照说明进行操作

【讨论】:

    【解决方案4】:

    修正: ...

        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.google.android.gms:play-services:12.0.1'
        implementation 'com.mcxiaoke.volley:library:1.0.19'
        implementation 'com.google.firebase:firebase-core:12.0.1'
        testImplementation 'junit:junit:4.12'
    }
    
    //apply plugin: 'com.google.gms.google-services'
    

    谢谢

    【讨论】:

    • 我很高兴你解决了这个问题
    • 顺便说一句,无需注释最后一行,它只适用于它,唯一需要的更改是返回到 firebase 版本 12.0.1 !
    猜你喜欢
    • 1970-01-01
    • 2019-09-01
    • 2018-05-14
    • 2017-04-25
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    相关资源
    最近更新 更多