Migrate to AndroidX

Chris Chen
1 min readAug 13, 2019
Android Q

Android official website provides a page to introduce how to migrate your existing project to AndroidX. Here is my migration step.

1. You have to add these two attrs in your gradle.properties

android.useAndroidX=true
android.enableJetifier=true

2. Update your compileSdkVersion, targetSdkVersion to 28. Like the below example.

compileSdkVersion 28
defaultConfig {
applicationId "com.your.package"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.support.test.runner.AndroidJUnitRunner"
}

3. upgrade your dependencies to the AndroidX newest. For dependencies, the version can refer to maven.

4. You need to modify your layout and .java/.kt since the package name is using AndroidX for now. Like:

android.support.constraint.ConstraintLayout => androidx.constraintlayout.widget.ConstraintLayoutandroid.support.v4.widget.SwipeRefreshLayou => androidx.swiperefreshlayout.widget.SwipeRefreshLayoutandroid.support.v7.widget.RecyclerView => androidx.recyclerview.widget.RecyclerViewandroid.support.v7.widget.CardView => androidx.cardview.widget.CardViewandroid.support.v7.widget.Toolbar => androidx.appcompat.widget.Toolbarandroid.support.design.widget.TextInputLayout => com.google.android.material.textfield.TextInputLayout...etc

Can check Class Mapping

Finally, we can use the dependencies graph to check if any conflict occurs.

//stagingDebug need replace with your product flavor name.
> ./gradlew -q dependencies app:dependencies --configuration stagingDebugAndroidTestCompileClasspath

If you need to check changes between before & after. You can refer to my migrated pr at Github here

--

--