官方文檔:
https://developer.android.com/topic/libraries/support-library/androidx-overview
參考:
https://mp.weixin.qq.com/s/JcviqDZ8To3ZEL2H0kVukA
https://github.com/bumptech/glide/issues/3185
AndroidStudio從3.1.x升級到3.2.x冗恨,在遷移項目的過程中有不少的坑
在project的build.gradle中配置升級的版本增显,我的版本如下:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
如果project中的build.gradle里有 bintray 的使用,如下:
dependencies {
classpath 'com.novoda:bintray-release:0.8.1'
}
在module的build.gradle中關(guān)于apply的引用要注釋掉什往,否則會導(dǎo)致問題软能,報
com.novoda.gradle.release.AndroidLibrary$LibraryUsage.getGlobalExcludes()Ljava/util/Set
的錯誤
//apply plugin: 'com.novoda.bintray-release'
在gradle.properties中配置:
useAndroid表示當(dāng)前項目是否啟動androidx迎捺,如果啟動就是true;
enableJetifier表示是否將依賴包遷移到androidx中去
android.useAndroidX = true
android.enableJetifier = true
buildToolsVersion的版本也要改為28.0.3,否則會提示:
The specified Android SDK Build Tools version (27.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
在AndroidStudio選項欄中選擇操作查排,將項目遷移到androidx凳枝,中間會提示是否要打包備份
Refactor > Migrate to AndroidX
3.2.x以后的版本對項目中的命名要求很嚴格,在androidx環(huán)境:
同一個xml布局中同名id不允許編譯和運行
attr屬性下不能定義android已有的屬性
報名必須使用小寫字母
......等等(就不一一列舉了雹嗦,項目中尚未遇到其他的)
com.android.support.xxx庫中的東西在項目遷移到androidx以后范舀,都不用再使用了合是,根據(jù)官方文檔androidx是對support包的整理,可以通過運行項目锭环,找到對應(yīng)的布局中的錯誤聪全,可以通過全局搜索找到布局中對view的引用,布局一般涉及到以下幾個View的改動:
NestedScrollView辅辩,TabLayout难礼,RecyclerView,CoordinatorLayout玫锋,CollapsingToolbarLayout蛾茉,ConstraintLayout,ViewPager 撩鹿,Group
例如Group:
會從
android.support.constraint.Group
遷移到
androidx.constraintlayout.widget.Group
項目中引用的庫一起尚未支持androidx谦炬,列如Glide圖片加載庫
網(wǎng)上的做法是:
implementation "com.android.support:support-annotations:28.0.0-alpha3"
annotationProcessor "com.android.support:support-annotations:28.0.0-alpha3"
親測可用,因為我本地庫的版本都是“28.0.0”节沦,所以我沒有使用“28.0.0-alpha3”