Google Auth迁移到androidx:SignInHubActivity未实现生命周期 [英] Google Auth migrating to androidx: SignInHubActivity does not implement Lifecycle

查看:192
本文介绍了Google Auth迁移到androidx:SignInHubActivity未实现生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

迁移到AndroidX后,我遇到了以下与Google Auth库有关的问题:

After the migration to AndroidX i'am facing this the following issue with the Google Auth lib:

在Android 9 API 28上:

On Android 9 API 28:

java.lang.IncompatibleClassChangeError: Class 'com.google.android.gms.auth.api.signin.internal.SignInHubActivity' does not implement interface 'androidx.lifecycle.LifecycleOwner' in call to 'androidx.lifecycle.Lifecycle androidx.lifecycle.LifecycleOwner.getLifecycle()' (declaration of 'androidx.lifecycle.LiveData' appears in /data/app/fourbottles.bsg.workinghours4b-G1onPKgFFE-l3aqjx0qDJw==/split_lib_dependencies_apk.apk)
    at androidx.lifecycle.LiveData.observe(LiveData.java:172)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.setCallback(LoaderManagerImpl.java:100)
    at androidx.loader.app.LoaderManagerImpl.createAndInstallLoader(LoaderManagerImpl.java:400)
    at androidx.loader.app.LoaderManagerImpl.initLoader(LoaderManagerImpl.java:421)
    at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.zzn(Unknown Source:80)
    at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.onActivityResult(Unknown Source:68)
    at android.app.Activity.dispatchActivityResult(Activity.java:7454)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4353)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4402)
    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

在Android 5.0.2 API 22上

On Android 5.0.2 API 22

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.lifecycle.Lifecycle$State androidx.lifecycle.Lifecycle.getCurrentState()' on a null object reference
    at androidx.lifecycle.LiveData.observe(LiveData.java:172)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.setCallback(LoaderManagerImpl.java:100)
    at androidx.loader.app.LoaderManagerImpl.createAndInstallLoader(LoaderManagerImpl.java:400)
    at androidx.loader.app.LoaderManagerImpl.initLoader(LoaderManagerImpl.java:421)
    at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.zzn(Unknown Source)
    at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.onActivityResult(Unknown Source)
    at android.app.Activity.dispatchActivityResult(Activity.java:6139)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3535)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3582) 
    at android.app.ActivityThread.access$1300(ActivityThread.java:144) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5221) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我正在使用以下lib版本:

I'am using the following lib versions:

implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.multidex:multidex:2.0.1'

我一开始进行意图的活动,代码就会崩溃:

The code is crashing as soon as i start an activity with the intent:

val signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient)
startActivityForResult(signInIntent, LOGIN_WITH_GOOGLE_CODE)

我在settings.gradle文件中具有以下属性:

I have the following properties into the settings.gradle file:

android.useAndroidX=true
android.enableJetifier=true

Google Auth库不支持通过AndroidX库进行身份验证吗?

The Google Auth lib doesn't support authentication with AndroidX libs?

是否有一种方法可以从具有支持的lib行为的androidX lib中启动意图?

Is there a way to start an intent from an androidX lib with the supported lib behaviour?  

我接受Java和Kotlin语言的答案.

I accept answers in both java and kotlin languages.

更新1:27.12.2017

Update 1: 27.12.2017

创建Google api客户端:

Google api client creation:

 GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();

 googleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
                .build();

可能是由于enableAutoManage吗?

我设法用以下代码登录:

I managed to login with the following piece of code:

Task<GoogleSignInAccount> sign = googleSignInClient.silentSignIn();
GoogleSignInAccount result = sign.getResult();

因此,我认为凭据或其他配置文件没有问题.这样,用户将无法选择帐户.

So i think there is no problem with the credentials or the other configuration files. In this way the user won't be able to choose an account.

我认为Jetifier失败的原因相同.

I think that Jetifier is failing in same way.

使用API​​ 27时,我会遇到相同的错误.

With API 27 i'am getting the same error.

推荐答案

同样的问题!我刚刚添加了核心"依赖项,并将"appcompat"更改为最新的alpha版本,它有所帮助.

the same issue! I've just added the "core" dependency and bumped "appcompat" to the latest alpha version and it helped.

dependencies {

implementation "androidx.core:core:1.1.0-alpha03"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "androidx.annotation:annotation:1.0.1"
implementation "androidx.recyclerview:recyclerview:1.1.0-alpha01"
implementation "androidx.appcompat:appcompat:1.1.0-alpha01"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.cardview:cardview:1.0.0"
implementation "com.google.android.material:material:1.1.0-alpha02"

implementation "com.google.firebase:firebase-core:16.0.6"
implementation "com.google.firebase:firebase-auth:16.1.0"
implementation "com.google.firebase:firebase-storage:16.0.5"
implementation "com.google.firebase:firebase-perf:16.2.3"
implementation 'com.firebaseui:firebase-ui-database:4.3.0'

implementation "com.google.android.gms:play-services-auth:16.0.1"
implementation "com.google.android.gms:play-services-location:16.0.0"
implementation "com.google.android.gms:play-services-maps:16.0.0"
...
}

我使用:

compileSdkVersion 28
buildToolsVersion "28.0.3"

热门gradle.build:

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
    classpath 'com.google.gms:google-services:4.2.0'
    ...
}

gradle.properties:

android.debug.obsoleteApi=true
android.enableR8 = true
android.useAndroidX=true
android.enableJetifier=true

gradle包装器的gradle版本设置为gradle-4.10.1-all.zip.另外,我尝试无效/重新启动我的AS 3.3.希望它能对某人有所帮助.

gradle wrapper's gradle version is set to gradle-4.10.1-all.zip. Also I tried to Invalidate/restart my AS 3.3. Hope it will help somebody.

这篇关于Google Auth迁移到androidx:SignInHubActivity未实现生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆