迁移到 androidX 后出现 Manifest marge error

Manifest marge error after migrating to androidX

最近我开始学习新的 andoirdX 工件,包括 Android 架构组件。

阅读官方文档和 google 代码示例后,我已成功在我的项目和应用程序级别 Gradle 文件中添加了必要的依赖项。 他们如下

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'androidx.navigation.safeargs'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "_ _ _ _ _ _"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.google.android.material:material:1.0.0-rc01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'


def lifecycle_version = "2.0.0-beta01"
def room_version = "2.0.0-beta01"
def navigationVersion = '1.0.0-alpha06'
kapt "androidx.room:room-compiler:$room_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

implementation 'androidx.core:core-ktx:1.0.0-alpha1'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"

implementation "androidx.room:room-runtime:$room_version"
 }

在给予 Gradle 同步后一切正常,但是,它显示错误 "Manifest merge error please see logs for more info"

我仔细检查了 an app from google 存储库,一切正常。

请先收下我的拙见

最近我 运行 遇到了同样的问题,在给你解决方案之前我想告诉你最近几天,由于 Google 我们的日子提供了快节奏的开发工具-旧的开发技术发生了重大变化。

以jetpack为例,它是AndroidX的一部分,将其添加到您的项目中需要一些必要的步骤。此外,如果您像我一样使用 Android studio 的对话框来创建应用程序,您可能会遇到这些问题,包括您提到的问题。

原因是 android studio 仍然使用 Appcompat-v7,androidX 另一方面,使用

androidx.appcompat:appcompat:1.0.0

see the full artifacts listing

最重要的是,添加负责的依赖项后,您需要在 gradle.properties 文件

中添加这两行
android.useAndroidX=true
android.enableJetifier=true

不幸的是,如果已经走到这一步,您可能仍会面临

Manifest marge error

这是因为您的自动布局文件仍然有旧的类路径,例如

android.support.design.widget.CoordinatorLayout

应该是这样的androidx.constraintlayout.widget.ConstraintLayout

这个android.support.design.widget.AppBarLayout应该是com.google.android.material.appbar.AppBarLayout等等。

重新检查每个类路径后重建您的项目,一切都应该没问题。