Google 2018 IO 大会推出了 Android新的扩展库 AndroidX(Android 9.0),用于替换原来的 Android扩展库,将原来的android.替换成androidx.;只有包名和Maven工件名受到影响,原来的类名,方法名和字段名不会更改。官方早就推荐将support库迁移到androidx,因为后续support库不会再做更新。
迁移时只需要3.2版本及以上的android studio,在菜单refactor中点击migrate to androidx即可,该向导会提示需要做的更新。其中包括gradle版本至少3.2以上,compileSdkVersion 版本28以上。
1、常用依赖库对比
Old build artifact AndroidX build artifact
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
2、常用支持库类对比
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
————————————————