原来的 support 库转换到 androidx 都有相对于的库,官方地址如下:
需要科学上网
google 原 support 库对应的 androidx 库
例如原来的 com.android.support:appcompat-v7
库,转换到 androidx
对应的 库为:androidx.appcompat:appcompat
也就是将 app 中的 dependencies
implementation 'com.android.support:appcompat-v7:28.0.0'
改成
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
升级到 androidx
升级前,确保
android studio
版本在3.2
及以上
Android studio 支持一键升级, 点击 Refactor
-> Migrate to Androidx
即可
下面是手动升级
修改工程的 gradle.properties
在其中添加最后两项
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# 升级到 androidx 添加两行
android.useAndroidX=true
android.enableJetifier=true
修改 App 的 build.gradle 文件
修改项目依赖,
// 升级到 androidx 不能再使用 com.android.support
// 而要使用下方 androidx.appcompat
// implementation 'com.android.support:appcompat-v7:28.0.0'
// implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
如果项目还有其它依赖,需要逐个替换,原支持库对应的 androidx 支持库查看官方地址:
该链接需要科学上网,也可查看末尾的对应库
google 原 support 库对应的 androidx 库
需要注意的是,升级后,如果项目中有使用混淆等,同样需要逐个修改
修改项目中使用到原support 库的代码
例如原来项目中使用了 AppCompatActivity
导包时是 import android.support.v7.app.AppCompatActivity;
需要修改为 import androidx.appcompat.app.AppCompatActivity;
总的来说,库依赖的修改比较简单,需要逐个修改导包很麻烦
google 推荐的方式是开辟新分支,在新分支中升级
原support 库对应的 androidx 库
原support 库 | androix库 |
---|---|
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 | androidx.room: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 |