我正在尝试使用MVVM体系结构构建应用程序,为此,我在build.gradle
中实现了以下内容:
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.1.0-alpha03"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
}
但是然后我收到了
Manifest Merger Failed
错误: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:5:5-19:19 to override.
堆栈建议我将
tools:replace="android:appComponentFactory"
放入 list 中的<application>
元素,但这本身会导致更大的错误。谢谢。
最佳答案
如果您要使用AndroidX,则所有支持依赖项都必须是AndroidX。
其中包括appcompat-v7
和constraint-layout
。
AndroidX有一个migration table,它为您提供所有等效的支持库。
这将需要一些手动迁移,因为某些导入(AppCompatActivity,ConstraintLayout等)现在将无效。如果尝试构建,它将告诉您这些无效导入在构建错误日志中的位置。
还要确保找到XML中的AppCompat Views的任何用法(例如ConstraintLayout),并用其对应的AndroidX替代(只需开始输入View类名,Android Studio会建议正确的用法)。
关于android - 实现AndroidX依赖关系后, list 合并失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54153359/