x的最低實驗條件
AndroidStudio 3.2.0+
gradle:gradle-4.6以上
compileSdkVersion 28
本次實驗條件:
AndroidStudio 3.3 (AS3.3強制要求最低gradle版本為gradle-4.10-all)
gradle:gradle-4.10-all
使用AndroidX
如果要在新項目中使用AndroidX凫佛,則需要將compile SDK設(shè)置為Android 9.0(API級別28)或更高版本严拒,并在gradle.properties
文件中設(shè)置以下兩個Android Gradle插件標(biāo)志霜幼。
-
android.useAndroidX
:設(shè)置true
為時,Android插件使用相應(yīng)的AndroidX庫而不是支持庫。如果未指定,則默認(rèn)情況下為false
標(biāo)志 甥绿。 -
android.enableJetifier
:設(shè)置true
為時,Android插件會自動遷移現(xiàn)有的第三方庫,通過重寫其二進(jìn)制文件來使用AndroidX。如果未指定沫勿,則默認(rèn)情況下為false
標(biāo)志除盏。
AndroidX概述
AndroidX是Android團(tuán)隊用于在Jetpack中開發(fā)薛窥,測試胖烛,打包,發(fā)布和發(fā)布庫的開源項目 诅迷。
AndroidX是對原始Android 支持庫的重大改進(jìn) 洪己。與支持庫一樣,AndroidX與Android操作系統(tǒng)分開提供竟贯,并提供跨Android版本的向后兼容性答捕。AndroidX通過提供功能奇偶校驗和新庫完全取代了支持庫。此外屑那,AndroidX還包括以下功能:
- AndroidX中的所有軟件包都以字符串開頭拱镐,位于一致的命名空間
androidx
中。支持庫包已映射到相應(yīng)的androidx.*
包中持际。有關(guān)所有舊類和構(gòu)建工件的完整映射到新構(gòu)件沃琅,請參閱“ 包重構(gòu)”頁面。 - 與支持庫不同蜘欲,AndroidX軟件包是單獨維護(hù)和更新的益眉。這些
androidx
包使用嚴(yán)格的語義版本控制, 從版本1.0.0開始姥份。您可以單獨更新項目中的AndroidX庫郭脂。 - 所有新的支持庫開發(fā)都將在AndroidX庫中進(jìn)行。這包括維護(hù)原始支持庫工件和引入新的Jetpack組件澈歉。
其實就是對安卓過往v7,v4展鸡,design等系列包的一個整合,不用我們多次添加與核對版本號埃难,大大方便了我們的開發(fā)莹弊,真的是早就該這樣做了涤久。
開始體驗x
新建工程有個勾,勾上
創(chuàng)建完成后就會發(fā)現(xiàn)gradle.properties多了兩行
這兩行的作用主要是自動遷移任何尚未遷移到AndroidX命名空間的Maven依賴項目至AndroidX命名空間忍弛,如果是老項目現(xiàn)在想把整個工程其它包替換為androidx包响迂,在手動添加上面這兩行后直接使用AS Refactor->Migrate to AndroidX即可。
這個時候由于我本地還沒有androix這個庫,新建工程時的這兩個在線引用
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
也沒有引起AS給我自動下載下來androidx整個包细疚,感覺很奇怪蔗彤,就去官網(wǎng)隨便找了一個對應(yīng)的一個依賴,在線一填惠昔,導(dǎo)致它x包所有東西都下載下來了幕与,一切回歸正常挑势,在xml和java文件寫了好幾個以前分布在不同的包的類镇防,沒發(fā)現(xiàn)什么問題,至此體驗結(jié)束潮饱。
功臣包名:implementation 'com.google.android.material:material:1.0.0-rc01'
舊版本包與AndroidX對照表
舊包 | AndroidX |
---|---|
android.arch.core:common | androidx.arch.core:core-common:2.0.0-rc01 |
android.arch.core:core | androidx.arch.core:core:2.0.0-rc01 |
android.arch.core:core-testing | androidx.arch.core:core-testing:2.0.0-rc01 |
android.arch.core:runtime | androidx.arch.core:core-runtime:2.0.0-rc01 |
android.arch.lifecycle:common | androidx.lifecycle:lifecycle-common:2.0.0-rc01 |
android.arch.lifecycle:common-java8 | androidx.lifecycle:lifecycle-common-java8:2.0.0-rc01 |
android.arch.lifecycle:compiler | androidx.lifecycle:lifecycle-compiler:2.0.0-rc01 |
android.arch.lifecycle:extensions | androidx.lifecycle:lifecycle-extensions:2.0.0-rc01 |
android.arch.lifecycle:livedata | androidx.lifecycle:lifecycle-livedata:2.0.0-rc01 |
android.arch.lifecycle:livedata-core | androidx.lifecycle:lifecycle-livedata-core:2.0.0-rc01 |
android.arch.lifecycle:reactivestreams | androidx.lifecycle:lifecycle-reactivestreams:2.0.0-rc01 |
android.arch.lifecycle:runtime | androidx.lifecycle:lifecycle-runtime:2.0.0-rc01 |
android.arch.lifecycle:viewmodel | androidx.lifecycle:lifecycle-viewmodel:2.0.0-rc01 |
android.arch.paging:common | androidx.paging:paging-common:2.0.0-rc01 |
android.arch.paging:runtime | androidx.paging:paging-runtime:2.0.0-rc01 |
android.arch.paging:rxjava2 | androidx.paging:paging-rxjava2:2.0.0-rc01 |
android.arch.persistence.room:common | androidx.room:room-common:2.0.0-rc01 |
android.arch.persistence.room:compiler | androidx.room:room-compiler:2.0.0-rc01 |
android.arch.persistence.room:guava | androidx.room:room-guava:2.0.0-rc01 |
android.arch.persistence.room:migration | androidx.room:room-migration:2.0.0-rc01 |
android.arch.persistence.room:runtime | androidx.room:room-runtime:2.0.0-rc01 |
android.arch.persistence.room:rxjava2 | androidx.room:room-rxjava2:2.0.0-rc01 |
android.arch.persistence.room:testing | androidx.room:room-testing:2.0.0-rc01 |
android.arch.persistence:db | androidx.sqlite:sqlite:2.0.0-rc01 |
android.arch.persistence:db-framework | androidx.sqlite:sqlite-framework:2.0.0-rc01 |
com.android.support.constraint:constraint-layout | androidx.constraintlayout:constraintlayout:1.1.2 |
com.android.support.constraint:constraint-layout-solver | androidx.constraintlayout:constraintlayout-solver:1.1.2 |
com.android.support.test.espresso.idling:idling-concurrent | androidx.test.espresso.idling:idling-concurrent:3.1.0 |
com.android.support.test.espresso.idling:idling-net | androidx.test.espresso.idling:idling-net:3.1.0 |
com.android.support.test.espresso:espresso-accessibility | androidx.test.espresso:espresso-accessibility:3.1.0 |
com.android.support.test.espresso:espresso-contrib | androidx.test.espresso:espresso-contrib:3.1.0 |
com.android.support.test.espresso:espresso-core | androidx.test.espresso:espresso-core:3.1.0 |
com.android.support.test.espresso:espresso-idling-resource | androidx.test.espresso:espresso-idling-resource:3.1.0 |
com.android.support.test.espresso:espresso-intents | androidx.test.espresso:espresso-intents:3.1.0 |
com.android.support.test.espresso:espresso-remote | androidx.test.espresso:espresso-remote:3.1.0 |
com.android.support.test.espresso:espresso-web | androidx.test.espresso:espresso-web:3.1.0 |
com.android.support.test.janktesthelper:janktesthelper | androidx.test.jank:janktesthelper:1.0.1 |
com.android.support.test.services:test-services | androidx.test:test-services:1.1.0 |
com.android.support.test.uiautomator:uiautomator | androidx.test.uiautomator:uiautomator:2.2.0 |
com.android.support.test:monitor | androidx.test:monitor:1.1.0 |
com.android.support.test:orchestrator | androidx.test:orchestrator:1.1.0 |
com.android.support.test:rules | androidx.test:rules:1.1.0 |
com.android.support.test:runner | androidx.test:runner:1.1.0 |
com.android.support:animated-vector-drawable | androidx.vectordrawable:vectordrawable-animated:1.0.0 |
com.android.support:appcompat-v7 | androidx.appcompat:appcompat:1.2.0 |
com.android.support:asynclayoutinflater | androidx.asynclayoutinflater:asynclayoutinflater:1.0.0 |
com.android.support:car | androidx.car:car:1.0.0-alpha5 |
com.android.support:cardview-v7 | androidx.cardview:cardview:1.0.0 |
com.android.support:collections | androidx.collection:collection:1.0.0 |
com.android.support:coordinatorlayout | androidx.coordinatorlayout:coordinatorlayout:1.0.0 |
com.android.support:cursoradapter | androidx.cursoradapter:cursoradapter:1.0.0 |
com.android.support:customtabs | androidx.browser:browser:1.0.0 |
com.android.support:customview | androidx.customview:customview:1.0.0 |
com.android.support:design | com.google.android.material:material:1.0.0-rc01 |
com.android.support:documentfile | androidx.documentfile:documentfile:1.0.0 |
com.android.support:drawerlayout | androidx.drawerlayout:drawerlayout:1.0.0 |
com.android.support:exifinterface | androidx.exifinterface:exifinterface:1.0.0 |
com.android.support:gridlayout-v7 | androidx.gridlayout:gridlayout:1.0.0 |
com.android.support:heifwriter | androidx.heifwriter:heifwriter:1.0.0 |
com.android.support:interpolator | androidx.interpolator:interpolator:1.0.0 |
com.android.support:leanback-v17 | androidx.leanback:leanback:1.0.0 |
com.android.support:loader | androidx.loader:loader:1.0.0 |
com.android.support:localbroadcastmanager | androidx.localbroadcastmanager:localbroadcastmanager:1.0.0 |
com.android.support:media2 | androidx.media2:media2:1.0.0-alpha03 |
com.android.support:media2-exoplayer | androidx.media2:media2-exoplayer:1.0.0-alpha01 |
com.android.support:mediarouter-v7 | androidx.mediarouter:mediarouter:1.0.0 |
com.android.support:multidex | androidx.multidex:multidex:2.0.0 |
com.android.support:multidex-instrumentation | androidx.multidex:multidex-instrumentation:2.0.0 |
com.android.support:palette-v7 | androidx.palette:palette:1.0.0 |
com.android.support:percent | androidx.percentlayout:percentlayout:1.0.0 |
com.android.support:preference-leanback-v17 | androidx.leanback:leanback-preference:1.0.0 |
com.android.support:preference-v14 | androidx.legacy:legacy-preference-v14:1.0.0 |
com.android.support:preference-v7 | androidx.preference:preference:1.0.0 |
com.android.support:print | androidx.print:print:1.0.0 |
com.android.support:recommendation | androidx.recommendation:recommendation:1.0.0 |
com.android.support:recyclerview-selection | androidx.recyclerview:recyclerview-selection:1.0.0 |
com.android.support:recyclerview-v7 | androidx.recyclerview:recyclerview:1.0.0 |
com.android.support:slices-builders | androidx.slice:slice-builders:1.0.0 |
com.android.support:slices-core | androidx.slice:slice-core:1.0.0 |
com.android.support:slices-view | androidx.slice:slice-view:1.0.0 |
com.android.support:slidingpanelayout | androidx.slidingpanelayout:slidingpanelayout:1.0.0 |
com.android.support:support-annotations | androidx.annotation:annotation:1.0.0 |
com.android.support:support-compat | androidx.core:core:1.0.0 |
com.android.support:support-content | androidx.contentpager:contentpager:1.0.0 |
com.android.support:support-core-ui | androidx.legacy:legacy-support-core-ui:1.0.0 |
com.android.support:support-core-utils | androidx.legacy:legacy-support-core-utils:1.0.0 |
com.android.support:support-dynamic-animation | androidx.dynamicanimation:dynamicanimation:1.0.0 |
com.android.support:support-emoji | androidx.emoji:emoji:1.0.0 |
com.android.support:support-emoji-appcompat | androidx.emoji:emoji-appcompat:1.0.0 |
com.android.support:support-emoji-bundled | androidx.emoji:emoji-bundled:1.0.0 |
com.android.support:support-fragment | androidx.fragment:fragment:1.0.0 |
com.android.support:support-media-compat | androidx.media:media:1.0.0 |
com.android.support:support-tv-provider | androidx.tvprovider:tvprovider:1.0.0 |
com.android.support:support-v13 | androidx.legacy:legacy-support-v13:1.0.0 |
com.android.support:support-v4 | androidx.legacy:legacy-support-v4:1.0.0 |
com.android.support:support-vector-drawable | androidx.vectordrawable:vectordrawable:1.0.0 |
com.android.support:swiperefreshlayout | androidx.swiperefreshlayout:swiperefreshlayout:1.0.0 |
com.android.support:textclassifier | androidx.textclassifier:textclassifier:1.0.0 |
com.android.support:transition | androidx.transition:transition:1.0.0 |
com.android.support:versionedparcelable | androidx.versionedparcelable:versionedparcelable:1.0.0 |
com.android.support:viewpager | androidx.viewpager:viewpager |
:1.0.0
|com.android.support:wear |androidx.wear:wear:1.0.0
|com.android.support:webkit |androidx.webkit:webkit:1.0.0
參考文章:
【google官方】androix包
【google官方】現(xiàn)有項目遷移教程