Migrate from support package to AndroidX

Google will gradually abandon the upgrade and maintenance of the support package in the future. The newly developed package will only be updated on AndroidX, so it is recommended to switch as soon as possible.
In fact, it's relatively simple to switch AndroidX in Android Studio, basically you don't need to manually change the code, you can switch with one key.
Select the menu in turn: Refactor->Migrate to AndroidX..., a pop-up window will pop up, in which there is a check box: Backup project as Zip file, select this item to backup the project code before switching, or uncheck it. Click the "Migrate" button to start analyzing the entire project.
After the analysis is complete, the Refactoring Preview view will appear, which lists all the codes that need to be replaced. After checking it is correct, you can click the "Do Refactor" button to complete the switch.

After the switch is successful, you will find that in the gradle.properties file of the project, two new parameters will be added:
#Android plugin will use the corresponding AndroidX library instead of the support library.
android.useAndroidX=true
#The Android plugin will automatically migrate these libraries to use AndroidX by rewriting the binary files of existing third-party libraries.
android.enableJetifier=true

The following is the corresponding relationship of several commonly used libraries:
support library:
com.android.support:appcompat-v7:28.0.0
com.android.support:support-v4:28.0.0
com.android.support:support-annotations:27.1 .1
com.android.support.constraint:constraint-layout:1.1.3
AndroidX library:
androidx.appcompat : appcompat:1.0.0
androidx.legacy:legacy-support-v4:1.0.0
androidx.annotation:annotation:1.0. 0
androidx.constraintlayout:constraintlayout:1.1.3

Note:
1. The migration function of Android Studiod may not be able to complete all operations. If you find problems such as compilation errors or running crashes, please check the specific code and modify it manually.
2. To view the complete correspondence, please refer to the link: https://developer.android.google.cn/jetpack/androidx/migrate/artifact-mappings.

Guess you like

Origin blog.csdn.net/chenzhengfeng/article/details/112004864