How to Detect and Eliminate Jetifier Issues for Faster Android Builds
This article explains how to identify Jetifier warnings during Android compilation, why disabling Jetifier can break functionality, the limitations of the built‑in checkJetifier task, and presents a comprehensive solution using Gradle scripts, jetifier‑standalone, and custom tasks to migrate third‑party libraries to AndroidX while keeping build times low.
Background
During compilation optimization of the FoxFriend project, Build Analyzer warned that the Jetifier tool could improve the build.
Jetifier is a Gradle plugin that rewrites references to Android Support libraries in third‑party aar / jar files to their AndroidX equivalents, allowing an AndroidX‑based project to use older libraries.
Problem
Enabling android.useAndroidX=true and android.enableJetifier=true reduced build time by ~23 s, but the face‑recognition library hy-wbface-1.1.0.aar crashed at runtime because it still referenced removed Support classes.
Why checkJetifier Missed the Issue
The built‑in checkJetifier task scans Maven pom files for dependencies on com.android.support. It works only when a library publishes a complete pom. It fails for:
Directly bundled aar / jar files without a pom.
Locally repackaged Maven artifacts whose pom does not list the Support dependencies.
Both cases caused hy-wbface to be missed.
Dependency Detection Methods
To obtain a reliable list of third‑party binaries we use: gradle :app:androidDependencies – prints a concise dependency tree for a specific configuration. gradle :app:dependencies – prints the full dependency graph for all configurations.
A custom script that iterates over project.configurations.all and records each resolved module as group:name:version.
A recursive scan of the libs/ directory to collect local *.aar and *.jar files.
The script stores the results in a HashMap<String,String> where the key is the file name and the value is its absolute path.
Automated Migration with jetifier-standalone
Google provides the command‑line tool jetifier-standalone (see https://developer.android.google.cn/tools/jetifier?hl=en) which rewrites the bytecode of an aar / jar to replace Support classes with AndroidX equivalents.
Example command:
jetifier-standalone -i com.heytap.msp_3.1.0.aar -o Hy_com.heytap.msp_3.1.0.aar -l infoThe log contains lines such as TypeRewriter that confirm which classes were rewritten.
Custom Gradle Task Implementation
We added a Gradle extension function hyCheckjetifier() that:
Collects all Maven dependencies from every sub‑project.
Scans the local libs directory for aar / jar files.
Runs jetifier-standalone on each file and captures the output.
Prints the path of any library whose log contains TypeRewriter, indicating that it still uses Support libraries.
Then a custom task hyCheckjetifier is added to the app module:
task("hyCheckjetifier") {
group = "android"
dependsOn("checkJetifier")
doLast {
project.hyCheckjetifier()
}
}Running the task produces a report, e.g.:
cjf-checkjetify : =================================
cjf-checkjetify : Please use jetifier-standalone to remove android.support from below jar/aar:
cjf-checkjetify : =================================
.../stetho-1.5.0.aar
.../captcha-3.4.8.aar
.../hy-wbface-1.1.0.aar
.../open_sdk_3.5.12.2_r97423a8_lite.jarSolution Steps
Upgrade third‑party Maven libraries – e.g. upgrade com.facebook.stetho:stetho from 1.5.0 to 1.6.0, which no longer depends on Support libraries.
Repackage third‑party libraries – use jetifier-standalone to convert libraries such as captcha-3.4.8.aar to AndroidX, then publish the converted AAR to the internal FoxFriend Maven repository with a proper pom that lists all dependencies.
Update internal Maven artifacts – for libraries like hy-wbface, hy-amap, and hy-oppopush, run jetifier-standalone on the original AAR, replace the artifact in the internal Maven repo, and bump the version.
Convert local JARs – run jetifier-standalone on local JARs (e.g. open_sdk_3.5.12.2_r97423a8_lite.jar) and replace them with the generated AndroidX‑compatible versions.
Integrate the check into CI – add the hyCheckjetifier task to the CI pipeline so that every pull request triggers a scan and automatically notifies the commit author of any remaining Support dependencies.
Conclusion
By combining Gradle’s built‑in dependency inspection, custom scripts to locate all bundled binaries, and the jetifier-standalone tool, we can reliably detect hidden Support library usage, migrate those libraries to AndroidX, and prevent future build‑time regressions. The automated CI task ensures early warnings, keeping compilation fast and the app functional.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
