在Android开发者平台的修订历史记录上有这样一段话。
Revision 28.0.0 Production
(September 21, 2018)
This is the stable release of Support Library 28.0.0 and is suitable for use in production. This will be the last feature release under theandroid.support
packaging, and developers are encouraged to migrate to AndroidX.
传送门
这段话的大致意思就是说从28.0.0开始将不再更新Support包,开发者最好开始使用AndroidX开发。
而在AndroidX官方文档也说了AndroidX可以完全取代Support包。
我在新建了一个项目之后,直接到Github上找了个最新版的Butterknife添加进了依赖。添加完成后可以正常的编译,但是当我想运行的时候就报了如下错误
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory)
from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86
value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"'
to <application> element at AndroidManifest.xml:8:5-23:19 to override.
然后我就按照提示在AndroidManifest中添加了
tools:replace="android:appComponentFactory"
添加完成后发现并没有什么卵用。
我又把Butterknife删掉后运行了一下,发现确实是可以运行的,那么问题就出在添加的Butterknife身上。
猜测可能是因为Butterknife里引用的包和我自己的某些包冲突导致的。于是我在Android Studio 的Terminal命令行上查看了下项目所有引用的包
gradlew app(你的module名字) :dependencies
+--- com.jakewharton:butterknife:10.1.0
| \--- com.jakewharton:butterknife-runtime:10.1.0
| +--- com.jakewharton:butterknife-annotations:10.1.0
| | \--- androidx.annotation:annotation:1.0.0
| \--- androidx.core:core:1.0.0
| +--- androidx.annotation:annotation:1.0.0
| +--- androidx.collection:collection:1.0.0
| | \--- androidx.annotation:annotation:1.0.0
| +--- androidx.lifecycle:lifecycle-runtime:2.0.0
| | +--- androidx.lifecycle:lifecycle-common:2.0.0
| | | \--- androidx.annotation:annotation:1.0.0
| | +--- androidx.arch.core:core-common:2.0.0
| | | \--- androidx.annotation:annotation:1.0.0
| | \--- androidx.annotation:annotation:1.0.0
| \--- androidx.versionedparcelable:versionedparcelable:1.0.0
| +--- androidx.annotation:annotation:1.0.0
| \--- androidx.collection:collection:1.0.0 (*)
在Butterknife的包目录结构中出现了一个之前从没遇到过的以 androidx开头的包名,于是赶紧百度+google,结果就搜到了文章开头的那段话,而在StackOverflow上有人也指出了出现这个问题的所在,androidx和support不能同时出现在同一个项目中。知道了问题所在,那么解决办法也就出来了
- 使用老版本的butterknife
- 将项目中的support包都换成androidX包
我采用了第二种方式,毕竟谷歌以后都不打算更新support包了,作为使用者肯定要提前熟悉了。
下面,我再把androidx和support的对应表贴上来,如果你打算也使用第二种方式解决问题,那么把项目中的support替换成后面对应的androidx包就可以了。
再多提一句如果你把gradle中的包都替换好了以后,布局文件中如果也使用了support下的控件,记得也要全部改成androidx
例如
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
应改成
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
Old build artifact | AndroidX build artifact |
---|---|
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.0.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 |