拖了好久了,本想着等idea 2020.2再开始搞,结果人算不如天算啊。。。。
官方文档:developer.android.com/jetpack/androidx/migrate
1,项目结构
2,编译环境提升到28.0.0
官方表示这么个原因
这个文件末尾加两行
import后发现所有android support库都变成androidx的库了
此时,尝试运行,就会报各种找不到符号找不到类
5,替换依赖环境
5.1,全局依赖
全局通用配置文件config.gradle 变更为 config_x.gradle
对标官方的库映射:developer.android.com/jetpack/androidx/migrate/artifact-mappings
主要这么四个
5.2,单模块依赖
原来还有这个。。。。
只好上大招了。。。。
Replace All。。。。
5.3,调试
同步出现 Could not find androidx.appcompat:appcompat:28.0.0.
删 .idea/libraries/* 或者 File -> Invalide Cache / Restart...
重启后 执行 gradle sync,还是报 Could not find androidx.appcompat:appcompat:28.0.0.
跑到 公司maven下发现没这个版本,又跑到google maven下发现 也没有,只有1.0.0 - 1.0.3。。。。
有毒,好好地统一版本号不好吗。。。。。
挨个看了下最后的稳定版。。。。
顺便找到了官方的版本号列表: developer.android.com/jetpack/androidx/versions
报 Could not find com.google.android.material:material-rc01:1.1.0.
release All: com.google.android.material:material-rc01 -> com.google.android.material:material
又回去看了遍文档
。。。。
终于开始报代码错误了。。。。
6,替换类和xml
全局替换大法
android.support.annotation.NonNull -> androidx.annotation.NonNull
android.support.annotation.Nullable -> androidx.annotation.Nullable
android.support.annotation. -> androidx.annotation.
android.support.constraint. -> androidx.constraintlayout.widget.
android.support.v7.widget.RecyclerView -> androidx.recyclerview.widget.RecyclerView
android.support.v4.app.FragmentActivity -> androidx.fragment.app.FragmentActivity
android.support.v4.app.Fragment -> androidx.fragment.app.Fragment
android.support.v4.view. -> androidx.viewpager.widget.
android.support.v4.content. -> androidx.core.content.
android.support.v4.app.ActivityCompat -> androidx.core.app.ActivityCompat
android.arch.lifecycle. -> androidx.lifecycle.
android.support.design.widget. -> com.google.android.material.tabs.
android.support.design.widget.Snackbar -> com.google.android.material.snackbar.Snackbar
幸好用的小项目。。。。
批量替换出来问题修正
android.arch.lifecycle.Observer -> androidx.lifecycle.Observer
android.support.design.widget.AppBarLayout -> com.google.android.material.appbar.AppBarLayout
android.support.v7.widget.LinearLayoutManager -> androidx.recyclerview.widget.LinearLayoutManager
官方类映射文档 developer.android.com/jetpack/androidx/migrate/class-mappings
6.1,调试
a), 泛型
'removeObserver(Observer<T>)' in 'com.xxxxx.common.utils.LiveEventInstance.BusMutableLiveData' clashes with 'removeObserver(Observer<? super T>)' in 'androidx.lifecycle.LiveData'; both methods have same erasure, yet neither overrides the other
看起来是编译后类型擦除导致不知道什么类型了,先删掉 参数里的<T>试试。。。。
b), glide for androidx
之前版本时glide4.9,看源码里面引用的support,升级成4.11.0,源码引用就是androidx了;
相应的,glide proguard 也更新了下。
7,最后的冲刺
a),Could not find androidx.test:runner:1.0.2.
只有1.1.0、1.2.0.
b),Could not find androidx.test.espresso:espresso-core:3.0.2.
只有3.1.0、3.2.0;
c),打debug包竟然报proguard错误
果断祭出clean 重启大法。。。。
一发入魂,打包成功。。。。
尝试打release包
然后发现报错,竟然是部分xml的包替换错误。。。。
8,修正xml
android.support.design.widget.CoordinatorLayout -> androidx.coordinatorlayout.widget.CoordinatorLayout
android.support.design.widget.AppBarLayout -> com.google.android.material.appbar.AppBarLayout
android.support.design.widget.CollapsingToolbarLayout -> com.google.android.material.appbar.CollapsingToolbarLayout
9,升级基础库从support到androidx
//升级butterknife 从 9.0.0-rc1 到 10.2.1,回退
新的一天开始啦
2020年06月29日11:04:17
虽然能编译debug,但是 基础架构库 在idea里好多的红色警告呢....
另外貌似因为Proguard的报警 不能编译release。。。。
先升级基础库
大概是这么弄,不过gradle implementation是不是可以 1.0.+这种。。。。
拉个support库,用来继续迭代原support代码,默认分支develop/master变更为迭代androidx
a,类替换补充
android.support.v4.widget.SwipeRefreshLayout -> androidx.swiperefreshlayout.widget.SwipeRefreshLayout
这玩意竟然单独拆了个包出来,需要单独引入
c,测试类
android.support.test.runner.AndroidJUnitRunner -> androidx.test.runner.AndroidJUnitRunner
android.support.test.InstrumentationRegistry -> androidx.test.InstrumentationRegistry
android.support.test.runner.AndroidJUnit4 -> androidx.test.runner.AndroidJUnit4
10,梅开二度
使用了 升级后的基础库,debug没问题,但release依然报 proguard。。。
Exception while processing task java.io.IOException: Please correct the above warnings first.
然后发现报这么几个Waring
去SDK一看,30都出来了。。。。真可怕。。。。
果然,把编译环境从28,28.0.3 升级到了 29,29.0.3,打debug包 和打release包都成功了。。。。
再次搜了下代码貌似 android.support就这么一处,看了下官方demo这个地方still same....
贤者模式,养精蓄锐!
2020年06月30日15:46:18
官方文档:developer.android.com/jetpack/androidx/migrate
1,项目结构
其中scanc_displayer为待迁移的主app....
2,编译环境提升到28.0.0
官方表示这么个原因
执行迁移之前,请先将应用更新到最新版本。我们建议您将项目更新为使用支持库的最终版本:版本 28.0.0。这是因为,1.0.0 版本的 AndroidX 工件是与支持库 28.0.0 工件等效的二进制文件。3,配置gradle.properties
这个文件末尾加两行
android.useAndroidX=true android.enableJetifier=true注释
#Android 插件会使用对应的 AndroidX 库而非支持库 #Android 插件会通过重写现有第三方库的二进制文件,自动将这些库迁移为使用 AndroidX4,尝试重新import
import后发现所有android support库都变成androidx的库了
此时,尝试运行,就会报各种找不到符号找不到类
5,替换依赖环境
5.1,全局依赖
全局通用配置文件config.gradle 变更为 config_x.gradle
对标官方的库映射:developer.android.com/jetpack/androidx/migrate/artifact-mappings
主要这么四个
- com.android.support:appcompat-v7 ->
androidx.appcompat:appcompat
- com.android.support.constraint:constraint-layout ->
androidx.constraintlayout:constraintlayout
- com.android.support.test:runner -> androidx.test:runner
- com.android.support.test.espresso:espresso-core ->
androidx.test.espresso:espresso-core
apply from: "../../env/config_x.gradle"
5.2,单模块依赖
原来还有这个。。。。
只好上大招了。。。。
Replace All。。。。
- com.android.support:recyclerview-v7 -> androidx.recyclerview:recyclerview
- com.android.support:design ->
com.google.android.material:material-rc01 //这个很神奇啊
5.3,调试
同步出现 Could not find androidx.appcompat:appcompat:28.0.0.
删 .idea/libraries/* 或者 File -> Invalide Cache / Restart...
重启后 执行 gradle sync,还是报 Could not find androidx.appcompat:appcompat:28.0.0.
跑到 公司maven下发现没这个版本,又跑到google maven下发现 也没有,只有1.0.0 - 1.0.3。。。。
有毒,好好地统一版本号不好吗。。。。。
挨个看了下最后的稳定版。。。。
- appcompat:1.1.0
- constraintlayout: 1.1.0,1.1.3
- recyclerview:1.1.0
- material:1.1.0
顺便找到了官方的版本号列表: developer.android.com/jetpack/androidx/versions
报 Could not find com.google.android.material:material-rc01:1.1.0.
release All: com.google.android.material:material-rc01 -> com.google.android.material:material
又回去看了遍文档
。。。。
终于开始报代码错误了。。。。
6,替换类和xml
全局替换大法
android.support.annotation.NonNull -> androidx.annotation.NonNull
android.support.annotation.Nullable -> androidx.annotation.Nullable
android.support.annotation. -> androidx.annotation.
android.support.constraint. -> androidx.constraintlayout.widget.
android.support.v7.widget.RecyclerView -> androidx.recyclerview.widget.RecyclerView
android.support.v4.app.FragmentActivity -> androidx.fragment.app.FragmentActivity
android.support.v4.app.Fragment -> androidx.fragment.app.Fragment
android.support.v4.view. -> androidx.viewpager.widget.
android.support.v4.content. -> androidx.core.content.
android.support.v4.app.ActivityCompat -> androidx.core.app.ActivityCompat
android.arch.lifecycle. -> androidx.lifecycle.
android.support.design.widget. -> com.google.android.material.tabs.
android.support.design.widget.Snackbar -> com.google.android.material.snackbar.Snackbar
幸好用的小项目。。。。
批量替换出来问题修正
android.arch.lifecycle.Observer -> androidx.lifecycle.Observer
android.support.design.widget.AppBarLayout -> com.google.android.material.appbar.AppBarLayout
android.support.v7.widget.LinearLayoutManager -> androidx.recyclerview.widget.LinearLayoutManager
官方类映射文档 developer.android.com/jetpack/androidx/migrate/class-mappings
6.1,调试
a), 泛型
'removeObserver(Observer<T>)' in 'com.xxxxx.common.utils.LiveEventInstance.BusMutableLiveData' clashes with 'removeObserver(Observer<? super T>)' in 'androidx.lifecycle.LiveData'; both methods have same erasure, yet neither overrides the other
看起来是编译后类型擦除导致不知道什么类型了,先删掉 参数里的<T>试试。。。。
b), glide for androidx
之前版本时glide4.9,看源码里面引用的support,升级成4.11.0,源码引用就是androidx了;
相应的,glide proguard 也更新了下。
7,最后的冲刺
a),Could not find androidx.test:runner:1.0.2.
只有1.1.0、1.2.0.
b),Could not find androidx.test.espresso:espresso-core:3.0.2.
只有3.1.0、3.2.0;
c),打debug包竟然报proguard错误
Note: the configuration explicitly specifies 'android.widget.Space' to keep library class 'android.widget.Space'用gradlew命令打debug包竟然成功了。。。。
Note: there were 16 references to unknown classes.
You should check your configuration for typos.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 60 unkept descriptor classes in kept class members.
You should consider explicitly keeping the mentioned classes
(using '-keep').
(http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)
Note: there were 1 library classes explicitly being kept.
You don't need to keep library classes; they are already left unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#libraryclass)
Note: there were 32 unresolved dynamic references to classes or interfaces.
You should check if you need to specify additional program jars.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Warning: there were 2 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 2 unresolved references to library class members.
You probably need to update the library versions.
Alternatively, you may have to specify the option
'-dontskipnonpubliclibraryclassmembers'.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
Thread(Tasks limiter_1): destruction
> Task :a_displayer:transformClassesAndResourcesWithProguardForDfRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':a_displayer:transformClassesAndResourcesWithProguardForDfRelease'.
果断祭出clean 重启大法。。。。
一发入魂,打包成功。。。。
尝试打release包
然后发现报错,竟然是部分xml的包替换错误。。。。
8,修正xml
android.support.design.widget.CoordinatorLayout -> androidx.coordinatorlayout.widget.CoordinatorLayout
android.support.design.widget.AppBarLayout -> com.google.android.material.appbar.AppBarLayout
android.support.design.widget.CollapsingToolbarLayout -> com.google.android.material.appbar.CollapsingToolbarLayout
9,升级基础库从support到androidx
//升级butterknife 从 9.0.0-rc1 到 10.2.1,回退
新的一天开始啦
2020年06月29日11:04:17
虽然能编译debug,但是 基础架构库 在idea里好多的红色警告呢....
另外貌似因为Proguard的报警 不能编译release。。。。
先升级基础库
功能 | 版本 | 分支推进 |
support | v1.0.x | master -> support |
androidx | v1.1.x | master -> androidx |
kotlin | v2.0.x | master -> kotlin |
拉个support库,用来继续迭代原support代码,默认分支develop/master变更为迭代androidx
SENRSL:sample senrsl$ git branch support库同时使用了GitHub和bitbucket,github还好,bitbucket用的Amazonaws,各种推送失败。GFW,笔芯。。。。
SENRSL:sample senrsl$ git s
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .idea/caches/build_file_checksums.ser
no changes added to commit (use "git add" and/or "git commit -a")
SENRSL:sample senrsl$ git branch
* master
support
SENRSL:sample senrsl$ git checkout support
M .idea/caches/build_file_checksums.ser
Switched to branch 'support'
SENRSL:sample senrsl$ git branch
master
* support
SENRSL:sample senrsl$ git s
On branch support
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .idea/caches/build_file_checksums.ser
no changes added to commit (use "git add" and/or "git commit -a")
SENRSL:sample senrsl$ git push origin support
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'support' on GitHub by visiting:
remote: https://github.com/senRsl/sample-struct/pull/new/support
remote:
To github.com:senRsl/sample-struct.git
* [new branch] support -> support
SENRSL:sample senrsl$ git s
On branch support
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .idea/caches/build_file_checksums.ser
no changes added to commit (use "git add" and/or "git commit -a")
SENRSL:sample senrsl$ git checkout master
M .idea/caches/build_file_checksums.ser
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
SENRSL:sample senrsl$ git s
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .idea/caches/build_file_checksums.ser
no changes added to commit (use "git add" and/or "git commit -a")
SENRSL:sample senrsl$ git branch
* master
support
SENRSL:sample senrsl$
a,类替换补充
android.support.v4.widget.SwipeRefreshLayout -> androidx.swiperefreshlayout.widget.SwipeRefreshLayout
这玩意竟然单独拆了个包出来,需要单独引入
compileOnly "androidx.swiperefreshlayout:swiperefreshlayout:$ext.supportLibrary"b,示例中butterknife,从8.8.1升级到当前最新10.2.1
c,测试类
android.support.test.runner.AndroidJUnitRunner -> androidx.test.runner.AndroidJUnitRunner
android.support.test.InstrumentationRegistry -> androidx.test.InstrumentationRegistry
android.support.test.runner.AndroidJUnit4 -> androidx.test.runner.AndroidJUnit4
10,梅开二度
使用了 升级后的基础库,debug没问题,但release依然报 proguard。。。
Exception while processing task java.io.IOException: Please correct the above warnings first.
然后发现报这么几个Waring
Warning: com.google.android.material.snackbar.BaseTransientBottomBar$6: can't find referenced method 'android.graphics.Insets getMandatorySystemGestureInsets()' in library class android.view.WindowInsets搜了下说是要替换编译环境28到29。。。。
Warning: com.google.android.material.snackbar.BaseTransientBottomBar$6: can't find referenced class android.graphics.Insets
Warning: com.google.android.material.snackbar.BaseTransientBottomBar$6: can't find referenced class android.graphics.Insets
Warning: com.google.android.material.snackbar.Snackbar: can't find referenced method 'int getRecommendedTimeoutMillis(int,int)' in library class android.view.accessibility.AccessibilityManager
去SDK一看,30都出来了。。。。真可怕。。。。
果然,把编译环境从28,28.0.3 升级到了 29,29.0.3,打debug包 和打release包都成功了。。。。
再次搜了下代码貌似 android.support就这么一处,看了下官方demo这个地方still same....
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileProvider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider>
贤者模式,养精蓄锐!
2020年06月30日15:46:18
--
senRsl
2020年06月28日14:33:17
senRsl
2020年06月28日14:33:17
没有评论 :
发表评论