迁移到androidX后出现清单错误 [英] Manifest marge error after migrating to androidX

查看:406
本文介绍了迁移到androidX后出现清单错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始学习包括Android Architecture Components在内的新的andoirdX人工制品.

在阅读了官方文档和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同步后,一切正常,但是,它显示一条错误,提示清单合并错误,请参阅日志以获取更多信息"

我已经仔细检查了来自Google存储库的应用,一切似乎都很正常.

请提前接受我的谦虚感谢

解决方案

最近,我遇到了同样的问题,在为您提供解决方案之前,我想告诉您,由于提供了快节奏的开发工具,最近几天通过Google,我们悠久的开发技术已经发生了显着变化.

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

原因是android studio仍然使用Appcompat-v7,而androidX使用

androidx.appcompat:appcompat:1.0.0

查看完整的工件清单

首先,在添加负责的依赖项之后,您需要在gradle.properties文件中添加这两行

android.useAndroidX=true
android.enableJetifier=true

不幸的是,如果走了这么远,您可能仍然会面临

清单损坏错误

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

android.support.design.widget.CoordinatorLayout

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

这个android.support.design.widget.AppBarLayout应该是com.google.android.material.appbar.AppBarLayout,依此类推.

重新检查每个类路径后,将重新生成您的项目,并且一切都会正常.

Recently I have dived into learning new andoirdX artefacts including Android Architecture Components.

After reading through the officials docs and a google code samples I have successfully added the necessary dependencies in both my project and app level Gradle files. They are as follows

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
}

and

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"
 }

after giving Gradle sync everything worked fine, however, it showed an error saying "Manifest merge error please see logs for more info"

I have double checked with an app from google repository and everything seems normal.

Please accept my humble appreciation in advance

解决方案

Recently I have run into the same issue, Before giving you the solution I would like to tell you that in recent days, due to fast-paced development tools offered by Google our days-old development technique has changed significantly.

Take jetpack as an example, which is a part of AndroidX, and adding it into your projects requires some necessary steps. Moreover, if you are like me who uses Android studio's dialogs for creating an app, you are likely to have these kinds of issues including the one you have mentioned.

The reason for this is android studio still use Appcompat-v7, androidX on the other hand, uses

androidx.appcompat:appcompat:1.0.0

see the full artifacts listing

Above all, after adding responsible dependencies you need to add these two lines in you gradle.properties file

android.useAndroidX=true
android.enableJetifier=true

Unfortunately, if have come this far you would still probably face

Manifest marge error

this is because your automated layout files still have old classpaths such as

android.support.design.widget.CoordinatorLayout

which should be like this androidx.constraintlayout.widget.ConstraintLayout

this one android.support.design.widget.AppBarLayout should be com.google.android.material.appbar.AppBarLayout and So on.

After rechecking every classpath rebuild your project and everything should be fine.

这篇关于迁移到androidX后出现清单错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆