androidandroid-studioandroidxappcompatactivityandroid-jetifier

AndroidX conversion failure for library after Android Studio update to 3.3.1, is this a Jetifier bug?


I am using the library Chuck https://github.com/jgilfelt/chuck

I am not exactly sure when, but I did a Android Studio update recently and I think its probably the root cause, since it seems to be related to androidx conversion by jetifier, currently I am on Android Studio 3.3.1

I had Chuck working properly until before the update and I had been on AndroidX for quite a while, so is this a jetifier bug? Or is this expected and its high time I fork the 2 year old project, and convert it for AndroidX compatibility? This library is quite a boon and I really don't want to loose it.

When I look at Chuck source the BaseChuckActivity is extending the AppCompatActivity which already should be extending the LifecycleOwner class, so I came to the conclusion this seems to be a Jetifier bug.

The crash I am getting

java.lang.IncompatibleClassChangeError: Class 'com.readystatesoftware.chuck.internal.ui.TransactionActivity' 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/com.burstoralcare-k6cLY7GKXKIODVqHmJokmw==/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.readystatesoftware.chuck.internal.ui.TransactionActivity.onCreate(TransactionActivity.java:91)
    at android.app.Activity.performCreate(Activity.java:7136)
    at android.app.Activity.performCreate(Activity.java:7127)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    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)

Solution

  • So since there had been no activity for my question in SO, I went the extra mile to figure it out, I forked the Chuck project over updated everything to Androidx and updated target and compile SDKs to 28 and tada the CRASH STILL HAPPENED(it seemed to happen when using Loaders?), so even though the crash made it look like a jetifier bug it quite obviously wasn't a jetifier bug because now the new Chuck aar was AndroidX based completely(I went a bit further later on and even updated the language used by the library from Java to Kotlin) so I assumed the culprit was the androidx libraries, I looked at my appcompat libray because the crash was saying that the Chuck activity was not implementing LifeCycleOwner which was wrong because AppCompatActivity was a LifeCycleOwner, so I was at version "androidx.appcompat:appcompat:1.0.2" and changed it to "androidx.appcompat:appcompat:1.1.0-alpha02" and no more crashes!! (Even on the original library which has to be jetified)

    So what happened? I think some dependency I might have included must've been using a 1.1.0.variant or something else which had a buggy implementation and the newer library must've had precedence over my 1.0.2, so the other solution should be forcing the use of 1.0.2 for androidx.appcompat something like

    configurations.all {
        resolutionStrategy { 
            force 'androidx.appcompat:appcompat:1.0.2'
        }
    }
    

    I haven't tested the above but theoretically it should work if you want to stick to the stable version, otherwise you can just change to the alpha variant I mentioned above and it should definitely work.