解放雙手 - Android 開(kāi)發(fā)應(yīng)該嘗試的 UI 自動(dòng)化測(cè)試
1.說(shuō)明
We hope the division between android.* and androidx.* makes it more obvious which APIs are bundled with the platform, and which are static libraries for app developers that work across different versions of Android.
簡(jiǎn)單地說(shuō)就是新的庫(kù)可以在不同的Android版本上使用。比如之前我們?nèi)绻褂?code>support為27.1.1的相關(guān)依賴(lài)庫(kù)時(shí)。可能需要所有相關(guān)的support 庫(kù)都為27.1.1。如果其中有bug的話,可能需要所有的都去升級(jí),存在一個(gè)綁定關(guān)系,而且正式版的發(fā)布周期也很長(zhǎng)。
通過(guò)AndroidX,我們可以看到實(shí)時(shí)實(shí)現(xiàn)的特性和bug修復(fù)。升級(jí)個(gè)別依賴(lài),不需要對(duì)使用的所有其他庫(kù)進(jìn)行更新。這就和我們使用Github上的開(kāi)源庫(kù)一樣的,出了問(wèn)題,我們可以提出bug和意見(jiàn)。作者修復(fù)后,發(fā)布新版本,我們就可以直接替換使用了。更加的透明便捷。
2.變化
我選取了幾個(gè)常用依賴(lài)庫(kù),我們可以看看變化:
| Old build artifact | AndroidX build artifact |
|---|---|
| com.android.support:support-compat | androidx.core:core:1.0.0+ |
| com.android.support:appcompat-v7 | androidx.appcompat:appcompat:1.0.0+ |
| com.android.support:design | com.google.android.material:material:1.0.0+ |
| com.android.support:multidex | androidx.multidex:multidex:2.0.0+ |
| com.android.support:recyclerview-v7 | androidx.legacy:legacy-support-v4:1.0.0+ |
| com.android.support:viewpager | androidx.viewpager:viewpager:1.0.0+ |
| com.android.support:support-fragment | androidx.fragment:fragment:1.0.0+ |
當(dāng)然涉及的不止這些庫(kù),更詳細(xì)的變化內(nèi)容可以查看官方文檔。
我們可以添加appcompat依賴(lài)對(duì)比一下:
implementation 'com.android.support:appcompat-v7:28.0.0-beta1'或implementation 'androidx.appcompat:appcompat:1.0.0-beta01'123
可以看到詳細(xì)變化
??
同時(shí)我們看到viewpager、swiperefreshlayout、 coordinatorlayout 等一些UI組件被分離了出來(lái),這樣也是便于更好的使用,職責(zé)分明,以減輕不使用ProGuard 或 Multidex的應(yīng)用程序和測(cè)試的壓力。
3.影響
官方博客中有說(shuō)道,為了給開(kāi)發(fā)者一定遷移的時(shí)間,所以28.0.0的穩(wěn)定版本還是采用android.support。但是所有后續(xù)的功能版本都將采用androidx。
其實(shí)對(duì)于我們影響也不是很大,我們可以選擇不使用,畢竟不是強(qiáng)制的。但長(zhǎng)遠(yuǎn)看來(lái)還是有好處的。接受變化,擁抱變化也是我們程序猿需要有的精神,歡迎嘗試。
對(duì)于有寫(xiě)一些開(kāi)源項(xiàng)目的人,可能會(huì)有一些影響。比如你有一個(gè)關(guān)于RecyclerView的拓展庫(kù),那么你就需要去讓他支持AndroidX,否則你懂的。
我有去看了一下我們常用的butterknife、glide 等都已經(jīng)適配了AndroidX,不得不說(shuō)真是很良心。
4.遷移
如果一個(gè)一個(gè)去替換當(dāng)然很麻煩了,所以在Android Studio 3.2 Canary中添加了一鍵遷移的功能Refactor -> Migrate to AndroidX。
首先你的gradle版本至少為3.2.0以上,以及compileSdkVersion為28以上。
classpath 'com.android.tools.build:gradle:3.2.0+'1
如果你是一個(gè)新項(xiàng)目,如果使用AndroidX相關(guān)依賴(lài),需要在gradle.properties文件里添加配置:
android.useAndroidX=trueandroid.enableJetifier=true12
如果你想使用AndroidX,但是之前的不遷移,可以這樣配置:
android.useAndroidX=trueandroid.enableJetifier=false12
5.參考
工程師必備
- 項(xiàng)目客服
- 培訓(xùn)客服
- 平臺(tái)客服
TOP




















