Reputation: 121
I'm new in Android development and I've been recently assigned to an android project, which was not updated for more than a year. I got the below error when I try to build.
This project was made before android X and I have just migrated to the android X with android studio. Gradle version was 3.8 and now it is 7.0. When the migration and upgrade finished, I started to encounter this problem while building
Please guide me on how I should fix it.
FAILURE: Build failed with an exception.**
What went wrong: Execution failed for task ':app:packageDebug'. A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable Zip file 'C:\Users...\app\build\outputs\apk\debug\app-debug.apk' already contains entry 'AndroidManifest.xml', cannot overwrite
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 3s
Here my gradle files:
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'
// 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
}
Upvotes: 11
Views: 9839
Reputation: 355
this is the only working solution for me : in your build.gradle file add
android {
...
packagingOptions {
...
exclude 'resources.arsc'
exclude 'AndroidManifest.xml'
}
}
taken from Here
Upvotes: 4
Reputation: 1117
Depending on the Android Studio version and Gradle plugin version you are using, the culprit could be the new packaging tool: https://developer.android.com/studio/releases/gradle-plugin#zipflinger
The easiest way to fall back to using the older tool would be to add this line in the gradle.properties
file:
android.useNewApkCreator=false
Upvotes: 17
Reputation: 377
Verify that you do not have an extra AndroidManifest.xml in your project that is not part of a source set. When I fixed this in an old project recently, I found there was another AndroidManifest.xml in the resources/
directory.
Upvotes: 1