AndroidX迁移——弃用support库指南

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yin_ol/article/details/89421390

前言

Google I/O 2018上,Android团队宣布了AndroidX。它是Android团队用于在Jetpack中开发,测试,打包,版本和发布库的开源项目。与support库一样,每个AndroidX库都与Android操作系统分开提供,并提供跨Android版本的向后兼容性。

androidx 是对 android.support.xxx 包和其他google android支持库整理后的产物。由于之前的support包过于混乱,所以,google推出了 AndroidX。自support v7:28开始,大部分support包都会迁移到androidx下,所以建议开发者们尽早将项目转移到androidx下。

迁移步骤

1.先备份项目!

2.使用Android Studio自动迁移

在菜单栏中依次进入Refactor > Migrate to AndroidX,之后as会提示备份项目,如果已备份就不用勾选备份选项。
AS截图
迁移完成之后,gradle.properties里会多出这两行

android.useAndroidX=true
android.enableJetifier=true

如果你的项目中没有使用任何三方依赖,那么android.enableJetifier可以设置为false

3. 旧依赖包名与新包名对照表(建议使用Ctrl + F搜索)

执行Migrate to AndroidX完成之后,虽然常用的support包都会被转成对应的androidx里的包名,gradle或者maven里的部分依赖但还是有可能会未能转换成功,这时候需要我们手动修改。转载请注明出处,本文来自https://blog.csdn.net/yin_ol/article/details/89421390

原包名 新包名
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
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
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:1.0.0-alpha03
com.android.support:media2-exoplayer androidx.media2:media2-exoplayer
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



如有其他未列出的依赖,请参考 https://developer.android.google.cn/topic/libraries/support-library/refactor

展开阅读全文

没有更多推荐了,返回首页