如何使用 android 库中的 firebaseUI 优雅地构建 Unity 项目

Leo*_*ěch 5 android build unity-game-engine firebase firebaseui

我正在尝试使用 firebase google 和 facebook 登录创建一个游戏。我知道可以统一使用 firebase,但当存在像 FirebaseUI 这样的东西时,我不想单独创建两种登录方法。

所以我创建了带有 FirebaseUI 身份验证的 android 插件。我在新的 android 项目中测试了它,一切正常。但是当我在 unity 中使用我的插件时,我必须添加我自己的 gradle ( mainTemplate.gradle) 以及 firebaseUI 的依赖项。

问题是 firebase auth 库中有一个默认值,当构建游戏时,我的库(default_web_client_id等)中的值会被默认值覆盖。

几乎一周后我找到了解决方案,但我希望还有另一种方法。

我的解决方案:使用 firebase 构建 android 库,将库 ( .aar) 复制到 Assets/Plugins,将该库导出到 Idea,然后将整个文件values.xml(从google-services.json)和 facebook appId 复制到导出项目中的 res 文件夹。(然后从 Idea 构建)

它正在工作,但是通过这种方法,我default_web_client_id在项目中有 3 次(1x 来自我的库,1x 来自 FirebaseUI 依赖项,1x 来自 copy values.xml,覆盖它们)。这不是问题,但我认为没有必要。

有没有更优雅的方式来使用 firebaseUI 和 android 库?

mainTemplate(依赖部分):

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    def room_version = "1.1.1"

    implementation "android.arch.persistence.room:runtime:$room_version"
    annotationProcessor "android.arch.persistence.room:compiler:$room_version"
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'

    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation "android.arch.lifecycle:viewmodel:1.1.1"
    annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.facebook.android:facebook-android-sdk:4.41.0'

**DEPS**}
Run Code Online (Sandbox Code Playgroud)

Leo*_*ěch 1

经过更多实验后,我发现它取决于实现顺序,因此我将 **DEPS** 向上移动,现在它可以工作了。

所以解决方案很简单:

dependencies {
 implementation fileTree(dir: 'libs', include: ['*.jar'])
**DEPS**
 def room_version = "1.1.1"

 implementation "android.arch.persistence.room:runtime:$room_version"
 annotationProcessor "android.arch.persistence.room:compiler:$room_version"
 implementation 'com.google.code.gson:gson:2.8.2'
 implementation 'com.android.support:appcompat-v7:28.0.0'
 implementation 'com.android.support:support-v4:28.0.0'

 implementation "android.arch.lifecycle:extensions:1.1.1"
 implementation "android.arch.lifecycle:viewmodel:1.1.1"
 annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

 implementation 'com.google.firebase:firebase-core:16.0.8'
 implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
 implementation 'com.facebook.android:facebook-android-sdk:4.41.0'
}
Run Code Online (Sandbox Code Playgroud)

希望这对某人有帮助。