android - 实现AndroidX依赖关系后, list 合并失败

标签 android gradle mvvm

我正在尝试使用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-v7constraint-layout

AndroidX有一个migration table,它为您提供所有等效的支持库。

这将需要一些手动迁移,因为某些导入(AppCompatActivity,ConstraintLayout等)现在将无效。如果尝试构建,它将告诉您这些无效导入在构建错误日志中的位置。

还要确保找到XML中的AppCompat Views的任何用法(例如ConstraintLayout),并用其对应的AndroidX替代(只需开始输入View类名,Android Studio会建议正确的用法)。

关于android - 实现AndroidX依赖关系后, list 合并失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54153359/

相关文章:

android - Android Plugin for Gradle 中的 "minifyEnabled"和 "useProguard"有什么区别?

c# - 如何使用 DataAnnotations 检查 WPF 中是否存在有效数字

wpf - 使用MVVM在WPF DataGrid中显示组合框的用户友好方法

android - 如何为印地语将文本添加到语音中?

java - 如何解决java.lang.IllegalStateException?

java - 无法阻止 libgdx scene2d/ui/Label 半透明

java - 测试简单的Rxjava和gradle代码出现错误?

intellij-idea - 使用 Gradle 在 IntelliJ 中跳过测试

c# - WPF 中用户控件的输入和输出

android - 自定义 AlertDialog 页脚