LoginSignup
1
0

More than 5 years have passed since last update.

SignInHubActivity does not implement interface 'androidx.lifecycle.LifecycleOwner' というエラーを解決した

Posted at

AndroidXに移行して喜んでいたつかの間、エラーに苦しめられた。
どうにか解決したので記録しておく。

現象

  1. SuportLibrary28 から AndroidX に移行した。(Android StudioのMigrateで)
  2. Google SignInさせる画面があり、ダイアログでGoogleアカウントを選択する
  3. アカウント選択するとエラーでアプリが落ちる。

エラーメッセージ

'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/パッケージ名-vMvkbDRCPbVgROuCpJ301g==/base.apk!classes2.dex)

SignInHubActivityLifecycleOwnerが実装されていない、という内容?

エラーが発生する箇所のコード

Google SignInさせる画面をひらいた後でエラーで落ちてる

GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestEmail()
    .build();

GoogleApiClient client = new GoogleApiClient.Builder(this)
    .enableAutoManage(this, this)
    .addApi(Auth.GOOGLE_SIGN_IN_API, options)
    .build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(client);
startActivityForResult(signInIntent, SIGN_IN); //この後のアカウント選択で落ちてる

app/build.gradleの構成

app/build.gradle
android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

//〜省略〜
    implementation "androidx.appcompat:appcompat:1.0.2"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "com.google.android.gms:play-services-auth:16.0.1"
//〜省略〜

解決策

build.gradelの androidx.appcompat:appcompatのバージョンを上げて1.1.x系にすると発生しなくなった。

1.0.x系では絶対にエラーになるようだ。

app/build.gradle
//    implementation "androidx.appcompat:appcompat:1.0.2" <= エラーになる
    implementation "androidx.appcompat:appcompat:1.1.0-alpha03" // <= 修正後、エラーにならない

参考リンク

android - Google Auth migrating to androidx: SignInHubActivity does not implement Lifecycle - Stack Overflow
https://stackoverflow.com/questions/53899751/google-auth-migrating-to-androidx-signinhubactivity-does-not-implement-lifecycl

いやー解決してよかった
日本語の方法はあまりないみたい

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0