如何在Android中使用Firebase?

时间:2019-07-15 16:35:13

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

在将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
}

有什么帮助吗?

4 个答案:

答案 0 :(得分:1)

official docs所述,

“不要使用组合的播放服务目标。它带来了数十个库,使您的应用程序膨胀。而是仅指定您的应用使用的特定Google Play服务API。”

您不应使用组合播放服务库。而是尝试使用所需的特定库,然后尝试将特定库更新为17.0.0

答案 1 :(得分:0)

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

在这种情况下

更改此行:

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

有了这个:

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

答案 2 :(得分:0)

使用此Firebase documentation

或按照以下步骤操作:

工具-> Firebase->选择您的媒体库->按照说明

enter image description here enter image description here enter image description here

答案 3 :(得分:0)

修复: ...

    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'

谢谢