Reducing Android Studio Sync Time by Disabling Jetifier and Migrating to AndroidX
By disabling Jetifier through a custom Gradle plugin, fully migrating all Support libraries to AndroidX, and adding CI guardrails to block legacy dependencies, the team cut Android Studio sync time by roughly two and a half minutes and improved incremental build speed by 28% without sacrificing build stability.
Background : The team observed a long waiting period (≈10 minutes) after the Sync phase of Android Studio, caused by Jetifier converting Support libraries to AndroidX during the Gradle sync. Disabling Jetifier reduced sync time by about 2 minutes 30 seconds and cut incremental build time by 28%.
Problem Analysis : Gradle’s sync consists of three phases – initialization, configuration, and execution. No tasks are executed during sync; the delay originates from the configuration phase where Jetifier Transform processes each AAR/JAR. Log inspection showed repeated Transform jetified‑… with JetifyTransform messages.
Artifact Transform : Jetifier is implemented as a Gradle ArtifactTransform . It scans AAR/JAR inputs, rewrites class files via ASM and XML files via regex, then repackages the transformed artifacts for downstream consumption.
@CacheableTransform
abstract class JetifyTransform : TransformAction
{
}Dynamic Gradle Configuration : An attempt was made to set android.enableJetifier=false and android.useAndroidX=false via gradle.startParameter.projectProperties and gradle.startParameter.systemPropertiesArgs , but the values were read too late by AGP. The solution was to hook the BasePlugin after it is applied and replace the internal BooleanOption.ENABLE_JETIFIER values.
class TurnOffJetifierPlugin : Plugin
{
override fun apply(project: Project) {
project.plugins.withType(BasePlugin::class.java) {
val service = it.getProjectService() ?: return@withType
val projectOptions = service.projectOptions
val projectOptionsReflect = Reflect.on(projectOptions)
val optionValueReflect = Reflect.onClass(
"com.android.build.gradle.options.ProjectOptions$OptionValue",
projectOptions.javaClass.classLoader
)
val defaultProvider = DefaultProvider() { false }
val optionValueObj = optionValueReflect.create(projectOptions, BooleanOption.ENABLE_JETIFIER).get
()
Reflect.on(optionValueObj)
.set("valueForUseAtConfiguration", defaultProvider)
.set("valueForUseAtExecution", defaultProvider)
val map = getNewMap(projectOptionsReflect, optionValueObj)
projectOptionsReflect.set("booleanOptionValues", map)
}
}
private fun BasePlugin<*, *, *>.getProjectService() =
Reflect.on(this).field("projectServices").get
()
}The plugin works for the main project but fails for included builds because the init script applies the plugin after the value has already been read.
Support Dependency Migration : The ultimate goal is to eliminate all legacy Support libraries. The team performed three migration strategies:
Internal second‑party libraries: notified owners to run Android Studio’s “Refactor → Migrate to AndroidX” and publish the new AAR.
Third‑party libraries with source code: cloned, migrated with the same tool, and published to the internal Nexus.
Third‑party libraries without source: used the Jetifier CLI ( bJetifier -i [input.aar] -o [output.aar] ) and manually edited POM files to replace Support artifacts with AndroidX equivalents (referencing the AndroidX mapping CSV).
Pitfalls Encountered :
Package size differences: after migration, 32‑bit APK shrank by ~6 KB and 64‑bit by ~600 KB; most of the difference came from R.class and native .so files.
Nexus upload quirks: classifiers derived from AAR suffixes caused mismatched dependencies; missing POM files led to compile errors.
AndroidX dependency checks still emitted warnings even after Jetifier was disabled. Adding the flag com.android.build.gradle.internal.dependency.AndroidXDependencyCheck$AndroidXEnabledJetifierDisabled_issue_reported=true to gradle.properties silences these checks.
Future Guardrails : To prevent re‑introduction of Support libraries, the build configuration now excludes all known Support groups in every configuration, and an A8 check (similar to the one described in the earlier “Bilibili Android Build Optimization” article) runs in the CI pipeline to block commits that bring back legacy dependencies.
allprojects {
configurations.all { Configuration c ->
if (c.state == Configuration.State.UNRESOLVED) {
exclude group: 'com.android.support'
exclude group: 'android.arch.core'
exclude group: 'android.arch.lifecycle'
exclude group: 'android.arch.persistence.room'
exclude group: 'android.arch.persistence'
exclude group: 'com.squareup.leakcanary', module: "leakcanary-object-watcher-android-support-fragments"
}
}
}Conclusion : Since AndroidX superseded the Support library in 2021, keeping Jetifier enabled only slows builds. By fully migrating to AndroidX, disabling Jetifier, and enforcing dependency checks, the team achieved a noticeable reduction in sync and incremental build times while maintaining build stability.
Bilibili Tech
Provides introductions and tutorials on Bilibili-related technologies.
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.