升级到 androidX 后,Zip 文件“...”已包含条目“AndroidManifest.xml”,无法覆盖构建时错误

dku*_*urt 10 android gradle firebase android-gradle-plugin

我是Android开发新手,最近被分配到一个android项目,该项目已经一年多没有更新了。当我尝试构建时出现以下错误。

这个项目是在 android X 之前制作的,我刚刚使用 android studio 迁移到了 android X。Gradle 版本是 3.8,现在是 7.0。当迁移和升级完成后,我在构建时开始遇到这个问题

请指导我应该如何解决它。

FAILURE:构建失败并出现异常。**

出了什么问题:任务“:app:packageDebug”执行失败。执行 com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable Zip 文件 'C:\Users...\app\build\outputs\apk\debug\app-debug.apk' 时发生故障\app-debug.apk' 已包含条目 'AndroidManifest .xml',无法覆盖

尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。请访问https://help.gradle.org获取更多帮助 此版本中使用了已弃用的 Gradle 功能,使其与 Gradle 8.0 不兼容。使用“--warning-mode all”显示各个弃用警告。请参阅https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings 在 3 秒内构建失败

这是我的 gradle 文件:

build.gradle(模块:MyApp.app)

    apply plugin: 'com.android.application'
    apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 31
    defaultConfig {
        applicationId "com.myapp.app"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 108
        versionName "3.7"
        testInstrumentationRunner 'androidx.test.runner.AndroidJsUnitRunner'
        multiDexEnabled true
    }
    allprojects {
        repositories {
            jcenter()
            google()
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    namespace 'com.myapp.app'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('androidx.appcompat:appcompat:1.0.0', {
    exclude group: 'com.google.android.gms'
})
implementation('androidx.cardview:cardview:1.0.0', {
    exclude group: 'com.google.android.gms'
})
implementation('androidx.recyclerview:recyclerview:1.0.0', {
    exclude group: 'com.google.android.gms'
})
implementation('androidx.constraintlayout:constraintlayout:1.1.3', {
    exclude group: 'com.google.android.gms'
})
implementation('com.google.android:flexbox:1.0.0', {
    exclude group: 'com.google.android.gms'
})
implementation('com.google.android.material:material:1.0.0', {
    exclude group: 'com.google.android.gms'
})
implementation('com.squareup.picasso:picasso:2.71828', {
    exclude group: 'com.google.android.gms'
})
implementation('com.squareup.retrofit2:retrofit:2.3.0', {
    exclude group: 'com.google.android.gms'
})
implementation('com.squareup.retrofit2:converter-gson:2.3.0', {
    exclude group: 'com.google.android.gms'
})
implementation('com.squareup.okhttp3:okhttp:3.4.1', {
    exclude group: 'com.google.android.gms'
})
implementation('com.squareup.okhttp3:logging-interceptor:3.4.1', {
    exclude group: 'com.google.android.gms'
})
implementation('pl.droidsonroids.gif:android-gif-drawable:1.2.15', {
    exclude group: 'com.google.android.gms'
})
implementation 'com.google.android.gms:play-services-wallet:16.0.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-ads:17.0.0'
implementation 'com.google.android.gms:play-services-basement:16.1.0'
implementation('io.card:android-sdk:5.5.1', {
    exclude group: 'com.google.android.gms'
})
implementation('com.facebook.android:audience-network-sdk:5.0.0', {
    exclude group: 'com.google.android.gms'
})
implementation ('androidx.constraintlayout:constraintlayout:1.1.3',{
    exclude group: 'com.google.android.gms'
})
implementation ('androidx.legacy:legacy-support-v4:1.0.0',{
    exclude group: 'com.google.android.gms'
})

implementation platform('com.google.firebase:firebase-bom:29.0.3')

implementation ('com.google.firebase:firebase-crashlytics',{
    exclude group: 'com.google.android.gms'
})
implementation ('com.google.firebase:firebase-analytics',{
    exclude group: 'com.google.android.gms'
})

implementation ('com.google.firebase:firebase-core',{
    exclude group: 'com.google.android.gms'
})
implementation('com.google.firebase:firebase-messaging', {
    exclude group: 'com.google.android.gms'
})
implementation('androidx.work:work-runtime:2.7.1', {
    exclude group: 'com.google.android.gms'
})


implementation ('com.facebook.android:facebook-login:12.2.0',{
    exclude group: 'com.google.android.gms'
})
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

implementation('androidx.gridlayout:gridlayout:1.0.0', {
    exclude group: 'com.google.android.gms'
})

implementation ('androidx.multidex:multidex:2.0.0',{
    exclude group: 'com.google.android.gms'
})
/* implementation('com.smartyads:ad-container:0.4.9', {
    exclude group: 'com.google.android.gms'
    transitive = true
})*/
implementation ('com.inmobi.monetization:inmobi-ads:8.1.3',{
    exclude group: 'com.google.android.gms'
})

}

apply plugin: 'com.android.application'
Run Code Online (Sandbox Code Playgroud)

build.gradle(项目:MyApp)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        mavenLocal()
        flatDir {
            dirs '../libs'
        }
        maven { url "https://jitpack.io" }
        maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
        maven { url "https://dl.bintray.com/smartyads/maven/" }
        maven {
            url 'https://maven.google.com/'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

Bur*_*Dor 14

根据您使用的 Android Studio 版本和 Gradle 插件版本,罪魁祸首可能是新的打包工具:https://developer.android.com/studio/releases/gradle-plugin#zipflinger

回退到使用旧工具的最简单方法是在文件中添加以下行gradle.properties

android.useNewApkCreator=false
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,这对我有用(在从 Eclipse 导入的项目中构建单元测试时遇到相同的错误,即使构建的主应用程序没有此问题)。我仍然不明白为什么新的 APK 创建者会导致这个问题 - 知道这一点会很好,因为使用旧的 APK 创建者的选项在 Android Gradle 插件的 8.0 版本中被删除。 (3认同)

Jon*_*ler 0

确认您的项目中没有不属于源集的额外 AndroidManifest.xml。最近我在一个旧项目中修复这个问题时,我发现目录中还有另一个AndroidManifest.xml resources/