At Google I/O 2018, AndroidX was introduced as the official replacement for the legacy Android Support Library. This migration involves ranaming packages from android.* to androidx.*, while keeping all class names, method signatures, and field names unchanged. Only package names and Maven artifact identifiers are affected.
Key Changes in AndroidX
Common Dependency Mappings:
| Legacy Artifact | AndroidX Equivalent |
|---|---|
com.android.support:appcompat-v7:28.0.2 |
androidx.appcompat:appcompat:1.0.0 |
com.android.support:design:28.0.2 |
com.google.android.material:material:1.0.0 |
com.android.support:support-v4:28.0.2 |
androidx.legacy:legacy-support-v4:1.0.0 |
com.android.support:recyclerview-v7:28.0.2 |
androidx.recyclerview:recyclerview:1.0.0 |
com.android.support.constraint:constraint-layout:1.1.2 |
androidx.constraintlayout:constraintlayout:1.1.2 |
Class Name Mappings:
| Support Library Class | AndroidX Class |
|---|---|
android.support.v4.app.Fragment |
androidx.fragment.app.Fragment |
android.support.v4.app.FragmentActivity |
androidx.fragment.app.FragmentActivity |
android.support.v7.app.AppCompatActivity |
androidx.appcompat.app.AppCompatActivity |
android.support.v7.app.ActionBar |
androidx.appcompat.app.ActionBar |
android.support.v7.widget.RecyclerView |
androidx.recyclerview.widget.RecyclerView |
For a complete mapping reference, Google provides an official CSV file detailing all renamed artifacts and classes.
Migration Setup
Prerequisites:
- Android Studio 3.2 or higher
- Gradle plugin version 4.6 or newer
compileSdkVersionset to 28 or abovebuildToolsVersion28.0.2 or higher
Update the Gradle wrapper in gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Enable AndroidX in Project:
Add the following lines to gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
The android.useAndroidX flag enables AndroidX usage, while android.enableJetifier automatically converts third-party libraries that depend on the old Support Library to use AndroidX instead.
Update Dependencies:
Replace legacy dependencies in your module-level build.gradle:
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
Update Import Statements:
Replace old import paths in your Java/Kotlin files:
import androidx.appcompat.app.AppCompatActivity;
Automated Migration Tool:
In Android Studio 3.2+, use Refactor → Migrate to AndroidX to automate the conversion. Note that this requires compileSdkVersion ≥ 28; otherwise, you’ll see the error:
You need to have at least compileSdk 28 set in your module build.gradle to refactor to androidx
Potential Issues
A common problem arises when both Support Library and AndroidX dependencies coexist, causing build conflicts. Ensure all dependencies are fully migrated and no legacy artifacts remain.
Benefits of AndroidX
Although migration isn’t mandatory immediately, adopting AndroidX offers long-term advantages. It introduces a more modular and consistent package structure, reduces ecosystem fragmentation, and serves as the foundasion for modern Android development, including Jetpack components.