androidandroid-studioandroid-support-libraryandroidxandroid-jetifier

AndroidX Jetifier unable/failed to transform 3rd-party transitive dependency that still use Support Library


I've recently migrated my project to use AndroidX

My apps crashes, after I migrate to AndroidX, due to library still using Support Library. Here's a list of my 3rd-party dependencies/library, that failed to transform into AndroidX:

  1. com.clevertap.android:clevertap-android-sdk:3.4.2
  2. com.readystatesoftware.chuck:library:1.1.0
  3. com.ncapdevi:frag-nav:2.4.0
  4. jp.wasabeef:recyclerview-animators:2.3.0
  5. com.github.chivorns:smartmaterialspinner:1.1.6
  6. com.facebook.android:facebook-android-sdk:5.0.1
  7. com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:7.0.1 (I still cannot upgrade it to 10.x.x, because major API changes)
  8. com.github.nikartm:image-support:1.0.5

My Setups:

AS & AGP: 3.6.2
targetSdk: 29
minSdk: 16
Data & View Binding: Both enabled
Gradle DSL: Kotlin
Gradle: gradle-6.0.1-all

What I've done so far:

  1. Using Refactor -> Migrate to AndroidX tools from Android Studio, but ended-up force close it, because takes a long time
  2. android.enableJetifier=true & android.useAndroidX=true
  3. Using the shell scripts to manually mapping artifact, class and imports from Support Library to AndroidX, thanks @Danlew, also @Danlew mentioned in ADS '19 talks here
  4. Already checked my :app:dependencies that 3rd-party dependencies already migrated to use AndroidX artifacts, but only a few of them (failed for the above dependencies list)
  5. Deleting ./root_project/.idea, ./root_project/.gradle & ~/.gradle/caches (to fix compile-error/IDE error, references: AndroidX migrate dependency / libraries
  6. Understanding the jetifier: What is Jetifier? & official android docs
  7. Did a workaround to use AndroidX for annotation processor like: Glide & Dagger
  8. Checking the ~/.gradle directories for the jetified-* libs screenshot of my <code>~/.gradle</code> contents the jetified aar exist, unfortunately it's failed for clevertap & others libs listed above.

My conclusions, the jetifier works by rewriting the binary .class of our 3rd-party library if Support Library imports/class detected, and modify (jetified/mapping it) into AndroidX respectively.

But in my case, the dependencies listed above doesn't use correct AndroidX imports and resulting runtime crash, due to having a transitive dependent for Support Library.

Does jetifier currently doesn't support transitive dependency inside 3rd-party library as well? But, strangely it works for a few library (unlisted from above)

[UPDATED 1]

In the meantime (quickfix):

  1. I did downloading all the transitive dependencies of the libraries exhaustively one-by-one
  2. Using jetifier-standalone commands instead for the libraries aar
  3. Manually adding the libraries aar and its dependencies to app/build.gradle.kts as flatDirs

Is this really a workaround, is there anything better I can do?

[UPDATED 2]

I've using a maintained version of chuck as well. But found this same issue as well:

cannot generate view binders com.sun.tools.javac.code.Symbol$CompletionFailure: class file for android.support.v7.widget.AppCompatImageView not found

After checking my 3rd-party libs, I also ended-up manually adding the aar after I use jetifier-standalone for this library:

  1. com.clevertap.android:clevertap-android-sdk:3.4.2
  2. com.github.nikartm:image-support:1.0.5

Many also recommends to use api instead of implementation but for me, I don't want to bloated my project with transitive dependency

In other SO also recommends below:

  1. either remove the library,
  2. forked it to support androidx / waiting for the author to upgrade it
  3. manually using jetifier-standalone for those specicif libs, and include as local aar (this is my best approach, right now)

Unless the jetifier able to state this into official documentation, for its limitation: https://developer.android.com/jetpack/androidx/releases/jetifier

Seems like there's the least we can do, and hope, many of the 3rd-party authors will upgrade to AndroidX soon.

Here's a bonus article for references:

  1. You can use can-i-drop-jetifier libs to detects does your libs (transitively) needs jetifier enabled or not
  2. The time is right to migrate to AndroidX with this baby-steps
  3. Better structure packaging with AndroidX and also a headache along the way

Solution

  • Turns out my current workaround was using this approach: https://github.com/bumptech/glide/issues/3080#issuecomment-495430590

    Magical regex to turns a blacklist into a whiteliset

    android.jetifier.blacklist=^(?!.*[\\\\/](com\\.github\\.bumptech\\.glide|com\\.clevertap\\.android|com\\.facebook\\.android|com\\.github\\.nikartm|com\\.github\\.PierfrancescoSoffritti|com\\.github\\.prolificinteractive)[\\\\/]).*$
    

    If NoClassDef exceptions thrown, then I add the library package name into the android.jetifier.blacklist to whitelisted them.

    In the above cases, I'm trying to whitelist:

    1. glide
    2. clevertap
    3. nikartm
    4. facebook-sdk
    5. YoutubeAndroidPlayer (v7) still not using v10
    6. prolificinteractive