添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Why AndroidX

By the introduction of AndroidX, clear distinction is now made between the operating system packages and the support libraries or dependencies used to extend it. Going forward, the former (android OS) is going to be inside android and the support libraries inside androidx package hierarchy.

Not only does this make things clearer but it also enables using different versions of the former support library independently:

Before androidX:

Before androidx implementation "com.android.support:design:27.1.1" implementation "com.android.support:appcompat-v7:27.1.1" implementation "com.android.support:recyclerview-v7:27.1.1" implementation "com.android.support:support-dynamic-animation:27.1.1" implementation "com.android.support.constraint:constraint-layout:27.1.1" implementation "com.android.support:cardview-v7:27.1.1"
1
2
3
4
5
6
implementation "com.android.support:design:27.1.1"
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.android.support:recyclerview-v7:27.1.1"
implementation "com.android.support:support-dynamic-animation:27.1.1"
implementation "com.android.support.constraint:constraint-layout:27.1.1"
implementation "com.android.support:cardview-v7:27.1.1"
implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.browser:browser:1.0.0'
1
2
3
4
5
6
7
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.browser:browser:1.0.0'

This requires updating the support libraries to version 28.

2- Upgrade Android Gradle plugin and kotlin

Inside app build . gradle :

dependencies { classpath 'com.android.tools.build:gradle:3.4.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31"

3- Run migration tool

Run the migration tool in android studio from Refactor -- > Migrate to AndroidX .

Backup your project when prompted.

This process takes a while depending on the size of your project, so be patient.

4- Manual migration of some package names

If your project does not compile after the previous step, you will need to do this. Even after successful compilation you still might need to look into this. One example could be manual migration of android . support . design . R to com . google . android . material . R when being used as full name inside the code. For complete mappings refer to here .

Also if you are using RecyclerView for which the app : layoutManager is defined in the xml as a hardcoded string, the migration tool might not change it to androidX automatically, so do not forget to replace android . support . v7 . widget to androidx . recyclerview . widget in app : layoutManager . Not doing so causes crash at runtime.

5- Make release build and test it

The new shrinking tool (R8 shrinking tool) is enabled by default and might cause build problems. Disable it if running into release build issues by putting this in gradle . properties :

android . enableR8 = false

Test your app thoroughly. AndroidX migration can be a huge change depending on your project.

Happy Migrating!

Please help by spreading the word:
Category: Android Tags: , ,

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *