AndroidX ,support支持包

转载‘’

    https://blog.csdn.net/guolin_blog/article/details/97142065

一句话总结:

   1: AndroidX 是针对 Android Support Library进行的一次升级,升级内容主要在以下几个方面

      第一,包名。之前Android Support Library中的API,它们的包名都是在android.support.*下面的,而AndroidX库中所有API的包名都变成了在androidx.*下面。这是一个很大的变化,意味着以后凡是android.*包下面的API都是随着Android操作系统发布的,而androidx.*包下面的API都是随着扩展库发布的,这些API基本不会依赖于操作系统的具体版本。

     第二,命名规则。吸取了之前命名规则的弊端,AndroidX所有库的命名规则里都不会再包含具体操作系统API的版本号了。比如,像appcompat-v7库,在AndroidX中就变成了appcompat库。

  2:格式:implementation 'androidx.appcompat:appcompat:1.1.0'

    

  3:使用:比如之前你经常使用的RecyclerView、ViewPager等等库,在AndroidX中都会有一个对应的版本,只要改一下包名就可以完全无缝使用,用法方面基本上都没有任何的变化

     watch : AndroidX和Android Support Library中的库是非常不建议混合在一起使用的,因为它们可能会产生很多不兼容的问题。最好的做法是,要么全部使用AndroidX中的库,要么全部使用Android Support Library中的库​​​​​​​

4: 老项目迁移到 AndroidX 

     as 有一键迁移功能 :为此,Android Studio提供了一个一键迁移的功能,只需要对着你的项目名右击 → Refactor → Migrate to AndroidX,就会弹出如下图所示的窗口。

5: support 包和 AndroidX 版本对照

  

旧包AndroidX
android.arch.core:commonandroidx.arch.core:core-common:2.0.0-rc01
android.arch.core:coreandroidx.arch.core:core:2.0.0-rc01
android.arch.core:core-testingandroidx.arch.core:core-testing:2.0.0-rc01
android.arch.core:runtimeandroidx.arch.core:core-runtime:2.0.0-rc01
android.arch.lifecycle:commonandroidx.lifecycle:lifecycle-common:2.0.0-rc01
android.arch.lifecycle:common-java8androidx.lifecycle:lifecycle-common-java8:2.0.0-rc01
android.arch.lifecycle:compilerandroidx.lifecycle:lifecycle-compiler:2.0.0-rc01
android.arch.lifecycle:extensionsandroidx.lifecycle:lifecycle-extensions:2.0.0-rc01
android.arch.lifecycle:livedataandroidx.lifecycle:lifecycle-livedata:2.0.0-rc01
android.arch.lifecycle:livedata-coreandroidx.lifecycle:lifecycle-livedata-core:2.0.0-rc01
android.arch.lifecycle:reactivestreamsandroidx.lifecycle:lifecycle-reactivestreams:2.0.0-rc01
android.arch.lifecycle:runtimeandroidx.lifecycle:lifecycle-runtime:2.0.0-rc01
android.arch.lifecycle:viewmodelandroidx.lifecycle:lifecycle-viewmodel:2.0.0-rc01
android.arch.paging:commonandroidx.paging:paging-common:2.0.0-rc01
android.arch.paging:runtimeandroidx.paging:paging-runtime:2.0.0-rc01
android.arch.paging:rxjava2androidx.paging:paging-rxjava2:2.0.0-rc01
android.arch.persistence.room:commonandroidx.room:room-common:2.0.0-rc01
android.arch.persistence.room:compilerandroidx.room:room-compiler:2.0.0-rc01
android.arch.persistence.room:guavaandroidx.room:room-guava:2.0.0-rc01
android.arch.persistence.room:migrationandroidx.room:room-migration:2.0.0-rc01
android.arch.persistence.room:runtimeandroidx.room:room-runtime:2.0.0-rc01
android.arch.persistence.room:rxjava2androidx.room:room-rxjava2:2.0.0-rc01
android.arch.persistence.room:testingandroidx.room:room-testing:2.0.0-rc01
android.arch.persistence:dbandroidx.sqlite:sqlite:2.0.0-rc01
android.arch.persistence:db-frameworkandroidx.sqlite:sqlite-framework:2.0.0-rc01
com.android.support.constraint:constraint-layoutandroidx.constraintlayout:constraintlayout:1.1.2
com.android.support.constraint:constraint-layout-solverandroidx.constraintlayout:constraintlayout-solver:1.1.2
com.android.support.test.espresso.idling:idling-concurrentandroidx.test.espresso.idling:idling-concurrent:3.1.0
com.android.support.test.espresso.idling:idling-netandroidx.test.espresso.idling:idling-net:3.1.0
com.android.support.test.espresso:espresso-accessibilityandroidx.test.espresso:espresso-accessibility:3.1.0
com.android.support.test.espresso:espresso-contribandroidx.test.espresso:espresso-contrib:3.1.0
com.android.support.test.espresso:espresso-coreandroidx.test.espresso:espresso-core:3.1.0
com.android.support.test.espresso:espresso-idling-resourceandroidx.test.espresso:espresso-idling-resource:3.1.0
com.android.support.test.espresso:espresso-intentsandroidx.test.espresso:espresso-intents:3.1.0
com.android.support.test.espresso:espresso-remoteandroidx.test.espresso:espresso-remote:3.1.0
com.android.support.test.espresso:espresso-webandroidx.test.espresso:espresso-web:3.1.0
com.android.support.test.janktesthelper:janktesthelperandroidx.test.jank:janktesthelper:1.0.1
com.android.support.test.services:test-servicesandroidx.test:test-services:1.1.0
com.android.support.test.uiautomator:uiautomatorandroidx.test.uiautomator:uiautomator:2.2.0
com.android.support.test:monitorandroidx.test:monitor:1.1.0
com.android.support.test:orchestratorandroidx.test:orchestrator:1.1.0
com.android.support.test:rulesandroidx.test:rules:1.1.0
com.android.support.test:runnerandroidx.test:runner:1.1.0
com.android.support:animated-vector-drawableandroidx.vectordrawable:vectordrawable-animated:1.0.0
com.android.support:appcompat-v7androidx.appcompat:appcompat:1.0.0
com.android.support:asynclayoutinflaterandroidx.asynclayoutinflater:asynclayoutinflater:1.0.0
com.android.support:carandroidx.car:car:1.0.0-alpha5
com.android.support:cardview-v7androidx.cardview:cardview:1.0.0
com.android.support:collectionsandroidx.collection:collection:1.0.0
com.android.support:coordinatorlayoutandroidx.coordinatorlayout:coordinatorlayout:1.0.0
com.android.support:cursoradapterandroidx.cursoradapter:cursoradapter:1.0.0
com.android.support:customtabsandroidx.browser:browser:1.0.0
com.android.support:customviewandroidx.customview:customview:1.0.0
com.android.support:designcom.google.android.material:material:1.0.0-rc01
com.android.support:documentfileandroidx.documentfile:documentfile:1.0.0
com.android.support:drawerlayoutandroidx.drawerlayout:drawerlayout:1.0.0
com.android.support:exifinterfaceandroidx.exifinterface:exifinterface:1.0.0
com.android.support:gridlayout-v7androidx.gridlayout:gridlayout:1.0.0
com.android.support:heifwriterandroidx.heifwriter:heifwriter:1.0.0
com.android.support:interpolatorandroidx.interpolator:interpolator:1.0.0
com.android.support:leanback-v17androidx.leanback:leanback:1.0.0
com.android.support:loaderandroidx.loader:loader:1.0.0
com.android.support:localbroadcastmanagerandroidx.localbroadcastmanager:localbroadcastmanager:1.0.0
com.android.support:media2androidx.media2:media2:1.0.0-alpha03
com.android.support:media2-exoplayerandroidx.media2:media2-exoplayer:1.0.0-alpha01
com.android.support:mediarouter-v7androidx.mediarouter:mediarouter:1.0.0
com.android.support:multidexandroidx.multidex:multidex:2.0.0
com.android.support:multidex-instrumentationandroidx.multidex:multidex-instrumentation:2.0.0
com.android.support:palette-v7androidx.palette:palette:1.0.0
com.android.support:percentandroidx.percentlayout:percentlayout:1.0.0
com.android.support:preference-leanback-v17androidx.leanback:leanback-preference:1.0.0
com.android.support:preference-v14androidx.legacy:legacy-preference-v14:1.0.0
com.android.support:preference-v7androidx.preference:preference:1.0.0
com.android.support:printandroidx.print:print:1.0.0
com.android.support:recommendationandroidx.recommendation:recommendation:1.0.0
com.android.support:recyclerview-selectionandroidx.recyclerview:recyclerview-selection:1.0.0
com.android.support:recyclerview-v7androidx.recyclerview:recyclerview:1.0.0
com.android.support:slices-buildersandroidx.slice:slice-builders:1.0.0
com.android.support:slices-coreandroidx.slice:slice-core:1.0.0
com.android.support:slices-viewandroidx.slice:slice-view:1.0.0
com.android.support:slidingpanelayoutandroidx.slidingpanelayout:slidingpanelayout:1.0.0
com.android.support:support-annotationsandroidx.annotation:annotation:1.0.0
com.android.support:support-compatandroidx.core:core:1.0.0
com.android.support:support-contentandroidx.contentpager:contentpager:1.0.0
com.android.support:support-core-uiandroidx.legacy:legacy-support-core-ui:1.0.0
com.android.support:support-core-utilsandroidx.legacy:legacy-support-core-utils:1.0.0
com.android.support:support-dynamic-animationandroidx.dynamicanimation:dynamicanimation:1.0.0
com.android.support:support-emojiandroidx.emoji:emoji:1.0.0
com.android.support:support-emoji-appcompatandroidx.emoji:emoji-appcompat:1.0.0
com.android.support:support-emoji-bundledandroidx.emoji:emoji-bundled:1.0.0
com.android.support:support-fragmentandroidx.fragment:fragment:1.0.0
com.android.support:support-media-compatandroidx.media:media:1.0.0
com.android.support:support-tv-providerandroidx.tvprovider:tvprovider:1.0.0
com.android.support:support-v13androidx.legacy:legacy-support-v13:1.0.0
com.android.support:support-v4androidx.legacy:legacy-support-v4:1.0.0
com.android.support:support-vector-drawableandroidx.vectordrawable:vectordrawable:1.0.0
com.android.support:swiperefreshlayoutandroidx.swiperefreshlayout:swiperefreshlayout:1.0.0
com.android.support:textclassifierandroidx.textclassifier:textclassifier:1.0.0
com.android.support:transitionandroidx.transition:transition:1.0.0
com.android.support:versionedparcelableandroidx.versionedparcelable:versionedparcelable:1.0.0
com.android.support:viewpagerandroidx.viewpager:viewpager:1.0.0
com.android.support:wearandroidx.wear:wear:1.0.0
com.android.support:webkitandroidx.webkit:webkit:1.0.0

    6: 有以下几种情况不要入坑

    6.1 对于引入了 三方的东西.androidx 迁移还是很麻烦

  6.2  新项目中用的androidx,和原来的support v7不兼容出错

    

7: support包

     背景: 举个例子,当Android系统发布到3.0版本的时候,突然意识到了平板电脑的重要性,因此为了让Android可以更好地兼容平板,Android团队在3.0系统(API 11)中加入了Fragment功能。但是Fragment的作用并不只局限于平板,以前的老系统中也想使用这个功能该怎么办?于是Android团队推出了一个鼎鼎大名的Android Support Library,用于提供向下兼容的功能。比如我们每个人都熟知的support-v4库,appcompat-v7库都是属于Android Support Library的,这两个库相信任何做过Android开发的人都使用过。

   supportV4 

      

  supportV7

      

但是慢慢随着时间的推移,什么1.6、2.1系统早就已经被淘汰了,现在Android官方支持的最低系统版本已经是4.0.1,对应的API版本号是15。support-v4、appcompat-v7库也不再支持那么久远的系统了,但是它们的名字却一直保留了下来,虽然它们现在的实际作用已经对不上当初命名的原因了。

那么很明显,Android团队也意识到这种命名已经非常不合适了,于是对这些API的架构进行了一次重新的划分,推出了AndroidX。因此,AndroidX本质上其实就是对Android Support Library进行的一次升级,升级内容主要在于以下两个方面。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值