在动态功能模块中使用 Firebase 库

Using Firebase Libraries in a Dynamic Feature Module

我正在尝试在动态功能模块中使用 FirebaseAuth,但我得到了:

java.lang.AbstractMethodError: abstract method "com.google.android.gms.common.api.Api$Client com.google.android.gms.common.api.Api$AbstractClientBuilder.buildClient(android.content.Context, android.os.Looper, com.google.android.gms.common.internal.ClientSettings, java.lang.Object, com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks, com.google.android.gms.common.api.GoogleApiClient$OnConnectionFailedListener)"
        at com.google.android.gms.common.api.GoogleApi.zaa(Unknown Source:93)
        at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.<init>(Unknown Source:7)
        at com.google.android.gms.common.api.internal.GoogleApiManager.zab(Unknown Source:43)
        at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(Unknown Source:173)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at com.google.android.gms.internal.base.zap.dispatchMessage(Unknown Source:8)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)

我使用的是最新版本,我尝试使用较低版本但没有成功。

项目build.gradle.kts:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.0.0")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
        classpath("com.google.gms:google-services:4.3.3")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.1.1")
    }
}

应用build.gradle.kts:

plugins {
    id("com.android.application")
    id("kotlin-android")
    id("com.google.gms.google-services")
    id("com.google.firebase.crashlytics")
}

android {
    ...

    dynamicFeatures = mutableSetOf(":android:auth")
}

dependencies {
    implementation(AndroidDependencies.Core.FIREBASE_ANALYTICS) // 17.4.2
    implementation(AndroidDependencies.Core.FIREBASE_CRASHLYTICS) // 17.0.0
}

auth build.gradle.kts:

plugins {
    id("com.android.dynamic-feature")
    id("kotlin-android")
}

...

dependencies {
    implementation(project(":android:app"))
    implementation(AndroidDependencies.Core.FIREBASE_AUTH) // 19.3.1
}

有没有人遇到过这个?或者我在这里遗漏了什么?

好吧,如果有人遇到这个问题,我通过添加对 appauth

的依赖来解决它

应用程序:

dependencies {
    implementation(AndroidDependencies.Core.FIREBASE_ANALYTICS)
    implementation(AndroidDependencies.Core.FIREBASE_CRASHLYTICS)
    implementation(AndroidDependencies.Core.FIREBASE_AUTH)
}

授权:

dependencies {
    implementation(project(":android:app"))
    implementation(AndroidDependencies.Core.FIREBASE_AUTH)
}

如所述here

To enable support for dynamic feature modules, add the following dependency to your base module's build.gradle file:

dependencies {
    implementation 'com.google.firebase:firebase-dynamic-module-support:16.0.0-beta01'
}

我想,这意味着您必须将此行放在 app\build.gradle 文件中。以及放入功能模块的其他 Firebase 依赖项。