作为一个苦逼的android开发,google那边有什么动作,我们都得跟着左手右手一个慢动作,右手左手慢动作重播。这不google已经推出androidx有段时间了,但是很多的项目还是基于support做的。尤其作为一个裸辞跳槽准备的我来说,更是苦逼到家了。这不看到一个不错的MVVM框架——MVVMHabit,想要玩一玩,结果一看一看源码,还是基于support做的,就想着自己改造成androidx的,可是如果有亲手改造过的应该了解,androidx与support的对应关系那真的基本就是没有关系了,尤其support.design库里的控件,好多都拆解成单独的库,而不再是全部整合在一起了。但是只要你还用jetpack,就绕不开design库的切换,除此之外,还有animated-vector-drawable、palette等等库。
啥也不说了,动手改吧,多亏在官方提供了support到androidx的映射关系——工件映射,官方提供的是最新版的,懒得去看的,也可以往下看,是博客发布时的最新版,一般的也应该够用了。
其实起初的时候,只想着列一下下面的映射关系这篇博客就结束了,可以列到一半反应过来,或许有一些新入行的朋友,即便找到了映射关系,也不太清楚具体应该怎么用,毕竟我们在使用的时候,不是只写入下方的地址就好的,还需要添加对应的版本号,而这个版本号应该怎么确定呢?(了解这部分的大神可以直接跳过了,看下面的映射关系就可以)
这里就以MVVMHabit中的animated-vector-drawable为例,首先我们先来看看下面的映射关系怎么用:
PS:MVVMHabit这里使用的多module时的gradle提取统一配置,避免各个module版本不统一导致的异常,有兴趣了解的可以自行查找一下,我随便去百度搜了搜,找到了一个,可供参考:Gradle统一配置依赖版本,更详细的大家自己搜索吧
有了support的gradle地址了,下面就该找Androidx的地址了,其实这一步最简单,只需要在浏览器中ctrl + F搜索一下就可以了(mac或者不支持ctrl + F快捷键的浏览器只需要在当前页搜索就行),本博客还没有发布,我这里就以官网上搜索的结果为例了:
由于搜索框大小限制,我标注了一下,搜索的内容为:“com.android.support:animated-vector-drawable”,其实有一些特殊的,输入“animated-vector-drawable”也可以,毕竟我们只是为了找到这一条而已。
映射关系找到了,那下一步就应该是查找Androidx库的最新稳定版本号了,我能想到的有两种方案(问老同事不算啊)。
首先进入官方首页,在工件映射的页面也可以,搜索Androidx的路径。
请原谅网速一般,页面跳转比较慢,翻译成中文了是因为开了chrome插件,无视之就好。具体选择的时候,我也不知道选第几个了,录制了gif后测试了一下,第一条其实也可以(如下图)。
当然,也是有区别的,那就是在2019年9月5日更新版本中,是没有Alpha版本的,所以还是建议在搜索结果中选择最新的时间:
其实大家在正常使用AS的时候,应该也会发现,在dependencies中,如果我们引用的库一旦有了新版本,就会有提示:
因此我们可以利用AS的这个机制来获取自己想要使用的组件的最新版本是什么,由于不知道最新是什么,所以如果随意设置的时候,很可能已经超过了最新版本,所以这里我方法是设置为0,应该不会有比这个还小的版本了吧。
可以看到,警告会提示我们最新版本的组件是1.1.0,正好也与上面通过官网查看的结果相互做了个验证。调整好版本号后是直接放到当前maven的dependencies中,还是放到多module封装的统一配置文件中就随大家开心了。
好了,知道怎么用了,后面就上映射关系了
support库 | Androidx库 |
---|---|
android.arch.core:common | androidx.arch.core:core-common |
android.arch.core:core | androidx.arch.core:core |
android.arch.core:core-testing | androidx.arch.core:core-testing |
android.arch.core:runtime | androidx.arch.core:core-runtime |
android.arch.lifecycle:common | androidx.lifecycle:lifecycle-common |
android.arch.lifecycle:common-java8 | androidx.lifecycle:lifecycle-common-java8 |
android.arch.lifecycle:compiler | androidx.lifecycle:lifecycle-compiler |
android.arch.lifecycle:extensions | androidx.lifecycle:lifecycle-extensions |
android.arch.lifecycle:livedata | androidx.lifecycle:lifecycle-livedata |
android.arch.lifecycle:livedata-core | androidx.lifecycle:lifecycle-livedata-core |
android.arch.lifecycle:reactivestreams | androidx.lifecycle:lifecycle-reactivestreams |
android.arch.lifecycle:runtime | androidx.lifecycle:lifecycle-runtime |
android.arch.lifecycle:viewmodel | androidx.lifecycle:lifecycle-viewmodel |
android.arch.paging:common | androidx.paging:paging-common |
android.arch.paging:runtime | androidx.paging:paging-runtime |
android.arch.paging:rxjava2 | androidx.paging:paging-rxjava2 |
android.arch.persistence.room:common | android.arch.persistence.room:common |
android.arch.persistence.room:compiler | androidx.room:room-compiler |
android.arch.persistence.room:guava | androidx.room:room-guava |
android.arch.persistence.room:migration | androidx.room:room-migration |
android.arch.persistence.room:runtime | androidx.room:room-runtime |
android.arch.persistence.room:rxjava2 | androidx.room:room-rxjava2 |
android.arch.persistence.room:testing | androidx.room:room-testing |
android.arch.persistence:db | androidx.sqlite:sqlite |
android.arch.persistence:db-framework | androidx.sqlite:sqlite-framework |
com.android.support.constraint:constraint-layout | androidx.constraintlayout:constraintlayout |
com.android.support.constraint:constraint-layout-solver | androidx.constraintlayout:constraintlayout-solver |
com.android.support.test.espresso.idling:idling-concurrent | androidx.test.espresso.idling:idling-concurrent |
com.android.support.test.espresso.idling:idling-net | androidx.test.espresso.idling:idling-net |
com.android.support.test.espresso:espresso-accessibility | androidx.test.espresso:espresso-accessibility |
com.android.support.test.espresso:espresso-contrib | androidx.test.espresso:espresso-contrib |
com.android.support.test.espresso:espresso-core | androidx.test.espresso:espresso-core |
com.android.support.test.espresso:espresso-idling-resource | androidx.test.espresso:espresso-idling-resource |
com.android.support.test.espresso:espresso-intents | androidx.test.espresso:espresso-intents |
com.android.support.test.espresso:espresso-remote | androidx.test.espresso:espresso-remote |
com.android.support.test.espresso:espresso-web | androidx.test.espresso:espresso-web |
com.android.support.test.janktesthelper:janktesthelper | androidx.test.jank:janktesthelper |
com.android.support.test.services:test-services | androidx.test:test-services |
com.android.support.test.uiautomator:uiautomator | androidx.test.uiautomator:uiautomator |
com.android.support.test:monitor | androidx.test:monitor |
com.android.support.test:orchestrator | androidx.test:orchestrator |
com.android.support.test:rules | androidx.test:rules |
com.android.support.test:runner | androidx.test:runner |
com.android.support:animated-vector-drawable | androidx.vectordrawable:vectordrawable-animated |
com.android.support:appcompat-v7 | androidx.appcompat:appcompat |
com.android.support:asynclayoutinflater | androidx.asynclayoutinflater:asynclayoutinflater |
com.android.support:car | androidx.car:car-alpha5 |
com.android.support:cardview-v7 | androidx.cardview:cardview |
com.android.support:collections | androidx.collection:collection |
com.android.support:coordinatorlayout | androidx.coordinatorlayout:coordinatorlayout |
com.android.support:cursoradapter | androidx.cursoradapter:cursoradapter |
com.android.support:customtabs | androidx.browser:browser |
com.android.support:customview | androidx.customview:customview |
com.android.support:design | com.google.android.material:material-rc01 |
com.android.support:documentfile | androidx.documentfile:documentfile |
com.android.support:drawerlayout | androidx.drawerlayout:drawerlayout |
com.android.support:exifinterface | androidx.exifinterface:exifinterface |
com.android.support:gridlayout-v7 | androidx.gridlayout:gridlayout |
com.android.support:heifwriter | androidx.heifwriter:heifwriter |
com.android.support:interpolator | androidx.interpolator:interpolator |
com.android.support:leanback-v17 | androidx.leanback:leanback |
com.android.support:loader | androidx.loader:loader |
com.android.support:localbroadcastmanager | androidx.localbroadcastmanager:localbroadcastmanager |
com.android.support:media2 | androidx.media2:media2-alpha03 |
com.android.support:media2-exoplayer | androidx.media2:media2-exoplayer-alpha01 |
com.android.support:mediarouter-v7 | androidx.mediarouter:mediarouter |
com.android.support:multidex | androidx.multidex:multidex |
com.android.support:multidex-instrumentation | androidx.multidex:multidex-instrumentation |
com.android.support:palette-v7 | androidx.palette:palette |
com.android.support:percent | androidx.percentlayout:percentlayout |
com.android.support:preference-leanback-v17 | androidx.leanback:leanback-preference |
com.android.support:preference-v14 | androidx.legacy:legacy-preference-v14 |
com.android.support:preference-v7 | androidx.preference:preference |
com.android.support:print | androidx.print:print |
com.android.support:recommendation | androidx.recommendation:recommendation |
com.android.support:recyclerview-selection | androidx.recyclerview:recyclerview-selection |
com.android.support:recyclerview-v7 | androidx.recyclerview:recyclerview |
com.android.support:slices-builders | androidx.slice:slice-builders |
com.android.support:slices-core | androidx.slice:slice-core |
com.android.support:slices-view | androidx.slice:slice-view |
com.android.support:slidingpanelayout | androidx.slidingpanelayout:slidingpanelayout |
com.android.support:support-annotations | androidx.annotation:annotation |
com.android.support:support-compat | androidx.core:core |
com.android.support:support-content | androidx.contentpager:contentpager |
com.android.support:support-core-ui | androidx.legacy:legacy-support-core-ui |
com.android.support:support-core-utils | androidx.legacy:legacy-support-core-utils |
com.android.support:support-dynamic-animation | androidx.dynamicanimation:dynamicanimation |
com.android.support:support-emoji | androidx.emoji:emoji |
com.android.support:support-emoji-appcompat | androidx.emoji:emoji-appcompat |
com.android.support:support-emoji-bundled | androidx.emoji:emoji-bundled |
com.android.support:support-fragment | androidx.fragment:fragment |
com.android.support:support-media-compat | androidx.media:media |
com.android.support:support-tv-provider | androidx.tvprovider:tvprovider |
com.android.support:support-v13 | androidx.legacy:legacy-support-v13 |
com.android.support:support-v4 | androidx.legacy:legacy-support-v4 |
com.android.support:support-vector-drawable | androidx.vectordrawable:vectordrawable |
com.android.support:swiperefreshlayout | androidx.swiperefreshlayout:swiperefreshlayout |
com.android.support:textclassifier | androidx.textclassifier:textclassifier |
com.android.support:transition | androidx.transition:transition |
com.android.support:versionedparcelable | androidx.versionedparcelable:versionedparcelable |
com.android.support:viewpager | androidx.viewpager:viewpager |
com.android.support:wear | androidx.wear:wear |
com.android.support:webkit | androidx.webkit:webkit |