19

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

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)

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)

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)

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

android.useAndroidX=true
android.enableJetifier=true

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

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

I accept answers in both java and kotlin languages.

Update 1: 27.12.2017

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();

It may be beacuse of enableAutoManage ?

Update 2: 28.12.2018

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.

I think that Jetifier is failing in same way.

With API 27 i'am getting the same error.

4bottiglie
  • 523
  • 7
  • 22
  • 1
    Do you have `implementation 'androidx.core:core:x.x.x'` in `build.gradle` file? – aminography Dec 25 '18 at 15:47
  • I added implementation 'androidx.core:core:1.0.1' into the build.gradle, invalidated cache, clean, rebuild, uninstall app, but i'am getting the same error. – 4bottiglie Dec 25 '18 at 16:49
  • If you are not using classes in core packages (https://developer.android.com/kotlin/ktx#core-packages), I think the only way (currently) to fix this problem is commenting the dependency of core. – aminography Dec 25 '18 at 17:41
  • I didn't have "androidx.core:core:1.0.1" in the first place, i added the line after your suggestion. There is no way to start it with the support lib behaviour? – 4bottiglie Dec 25 '18 at 17:49
  • I have tested this configuration in a new project. No problem happened. Is it possible to share more code? Post how you create `googleApiClient`. I have tested using `Auth.GOOGLE_SIGN_IN_API`. – aminography Dec 27 '18 at 18:57
  • I added update1 – 4bottiglie Dec 27 '18 at 19:27
  • Nope! Unfortunately `choose an account [DialogActivity]` opened successfully. I think something causes this problem which is hidden and not included in question information. Is it possible to share your project in a private [gitlab](https://about.gitlab.com/) repository and add me to it? – aminography Dec 27 '18 at 19:44
  • Unfortunately i can't share the entire project, it's already published and io have a lot of sensible data inside. Instead i can share single parts of code. – 4bottiglie Dec 27 '18 at 20:32
  • Sure, you can share a sample part of it which has this problem too. – aminography Dec 27 '18 at 20:51
  • @aminography Here is my Activity that is supposed to login with google and firebase: [FirebaseLoginActivity](https://pastebin.com/mSzM3Fhd) , i cleaned it a bit. I added the Update 2 – 4bottiglie Dec 28 '18 at 21:13
  • my [build.gradle](https://pastebin.com/t70KRi4j) – 4bottiglie Dec 28 '18 at 21:55
  • Sorry, did not help. – aminography Dec 30 '18 at 17:40
  • Did you found a solution? I have the same problem. – chrisonline Jan 06 '19 at 13:46

6 Answers6

18

I fixed this issue by using the latest version of the appcompat library:

implementation "androidx.appcompat:appcompat:1.1.0-rc01"

In previous versions the class AppCompatActivity did not implement the LifecycleOwner interface thus leading to the errors you observed.

phsource
  • 2,326
  • 21
  • 32
8

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"
...
}

I use:

compileSdkVersion 28
buildToolsVersion "28.0.3"

Top 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 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.

kot331107
  • 437
  • 1
  • 5
  • 9
  • I canfirm: i added androidx.core:core:1.1.0-alpha03, androidx.legacy:legacy-support-v4:1.0.0 and com.google.firebase:firebase-core. I invalidated cache, cleaned, rebuild. I also updated android studio to 3.3 (i don't know if was required) – 4bottiglie Jan 16 '19 at 20:44
  • @4bottiglie I suppose the bug was mostly connected with migration to AndroidX, not depending on version of AS...but who knows! :) – kot331107 Jan 16 '19 at 21:06
1

I found an work around until i find a fix or the library is updated:

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

if(sign.isSuccessful())
{
    GoogleSignInAccount resultAccount = sign.getResult();
    handleGoogleLogin(resultAccount);
}else
{
     Intent signInIntent = googleSignInClient.getSignInIntent();
     startActivityForResult(signInIntent, GOOGLE_SIGN_IN_CODE);
}

The code try to sign in silently, if the user didn't allow the sign in already, will start the intent. In my case the intent let me choose the account and crashes after tapping on the account. After the first tap, the silent signin will work.

4bottiglie
  • 523
  • 7
  • 22
1

Latest update: android.core:1.2.0-alpha02 still does not have that method in ComponentActivity.getLifeCycle()

I update to latest version of android.core:

dependencies {
    // ...
    def core_version = "1.2.0-alpha04"
    implementation "androidx.core:core:$core_version"
    implementation "androidx.core:core-ktx:$core_version"
}

The latest version can be found in https://developer.android.com/jetpack/androidx/releases/core

greensuisse
  • 1,727
  • 16
  • 18
0

I fixed the issue by adding this dependency to my gradle:

implementation 'androidx.arch.core:core-runtime:2.0.1-alpha01'

EDIT

Those are the versions i have used:

  • App level gradle compileSdkVersion = 28, buildToolsVersion = "28.0.3":

    implementation "com.google.android.gms:play-services-auth:16.0.1"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
    implementation 'androidx.arch.core:core-runtime:2.0.1-alpha01' 
    

    All com.android.support libraries are of version: 28.0.0

  • Project level gradle:

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

Note 1: If you have the below line, try to build without it:

implementation "androidx.legacy:legacy-support-v4:1.0.0"

Note 2: If you are building with Android Studio 3.3 (the latest at the time i am writing this answer) I got these errors when trying to migrate to androidX:

WARNING: API 'variant.getJavaCompiler()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'. It will be removed at the end of 2019. For more information, see https://d.android.com/r/tools/task-configuration-avoidance. To determine what is calling variant.getJavaCompiler(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace. Affected Modules: app

I could not manage to fix it, but just running the project with this error exists works surprisingly.

MBH
  • 16,271
  • 19
  • 99
  • 149
  • hi, i have cleaned, rebuild, invalidated cache, but unfortunately i have the same problem can you share all androix libs that you have into the project? – 4bottiglie Jan 15 '19 at 21:18
  • @4bottiglie I have updated the answer as for your request – MBH Jan 17 '19 at 06:12
0

I had same issue. I fixed it by changing following depedency

implementation 'androidx.core:core-ktx:1.1.0-alpha05'

to

implementation 'androidx.core:core-ktx:1.0.1'

So basically I am using stable release now.

Ankit Rathi
  • 161
  • 1
  • 5