20181112 AndroidStudio 3.2.1 迁移androidx

官方文档:
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中关于apply的引用要注释掉,否则会导致问题,报
com.novoda.gradle.release.AndroidLibrary$LibraryUsage.getGlobalExcludes()Ljava/util/Set
的错误

//apply plugin: 'com.novoda.bintray-release'

在gradle.properties中配置:
useAndroid表示当前项目是否启动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环境:
同一个xml布局中同名id不允许编译和运行
attr属性下不能定义android已有的属性
报名必须使用小写字母
......等等(就不一一列举了,项目中尚未遇到其他的)

com.android.support.xxx库中的东西在项目迁移到androidx以后,都不用再使用了,根据官方文档androidx是对support包的整理,可以通过运行项目,找到对应的布局中的错误,可以通过全局搜索找到布局中对view的引用,布局一般涉及到以下几个View的改动:

NestedScrollView,TabLayout,RecyclerView,CoordinatorLayout,CollapsingToolbarLayout,ConstraintLayout,ViewPager ,Group

例如Group:

会从
android.support.constraint.Group
迁移到
androidx.constraintlayout.widget.Group

项目中引用的库一起尚未支持androidx,列如Glide图片加载库
网上的做法是:

    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”

你可能感兴趣的:(20181112 AndroidStudio 3.2.1 迁移androidx)