23

I've cloned a github repository because I wanted to study the code, but when I tried to build it in Android Studio, I ran into some trouble. After adding the google maven repository (as prompted by Android Studio) and updating both the Gradle Plugin Version and the Grade Version (to 3.5.2 and to 5.4.1, respectively), the build fails because of the following error:

Cause: duplicate entry: META-INF/MANIFEST.MF

And this, to be more specific:

Caused by: java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF

Here is my project level build.gradle file:


    buildscript {
        repositories {
            jcenter()
            google()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.2'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
    
            maven {
                url 'https://maven.google.com'
            }
    
        }
    }

Here's my module build.gradle file (before trying anything):


    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion '28.0.3'
    
        defaultConfig {
            applicationId "com.thelittlenaruto.supportdesignexample"
            minSdkVersion 11
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation ('com.android.support:appcompat-v7:22.2.1')
        implementation ('com.android.support:design:22.2.1')
        implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
    }

Here's what I've tried so far:

  • Adding the following to the android section of my module build.gradle file:

    sourceSets {
            main{
                java{
                    exclude '**/META-INF/MANIFEST'
                    exclude '**/META-INF/MANIFEST.MF'
                    exclude 'META-INF/MANIFEST'
                    exclude 'META-INF/MANIFEST.MF'
                    exclude '!META-INF/MANIFEST.MF'
                }
            }
        }

  • Adding this:

    sourceSets.main.res.filter.exclude 'META-INF/MANIFEST'
        sourceSets.main.res.filter.exclude 'META-INF/MANIFEST.MF'

  • Also this:

    packagingOptions {
            apply plugin: 'project-report'
            exclude '**/META-INF/MANIFEST'
            exclude '**/META-INF/MANIFEST.MF'
            exclude 'META-INF/MANIFEST'
            exclude 'META-INF/MANIFEST.MF'
            exclude '!META-INF/MANIFEST.MF'
        }

  • And this:

    packagingOptions {
            pickFirst '**/META-INF/MANIFEST'
            pickFirst '**/META-INF/MANIFEST.MF'
            pickFirst 'META-INF/MANIFEST'
            pickFirst 'META-INF/MANIFEST.MF'
            pickFirst '!META-INF/MANIFEST.MF'
        }

  • This:

    aaptOptions {
            ignoreAssetsPattern "!META-INF/MANIFEST.MF"
            ignoreAssetsPattern "META-INF/MANIFEST.MF"
        }

I think I've tried mostly everything in this question: How to exclude certain files from Android Studio gradle builds?

Nothing worked.

After searching for a solution, I think the problem is that I have duplicated dependencies. So I've tried the following:


    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation ('com.android.support:appcompat-v7:22.2.1'){
            exclude module: 'support-v4'
        }
        implementation ('com.android.support:design:22.2.1')
        implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
    }

And this:


    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation ('com.android.support:design:22.2.1'){
            exclude module: 'support-v7'
        }
        implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
    }

I still get the same error.

What am I doing wrong?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Laila Campos
  • 801
  • 1
  • 8
  • 21
  • I have the same problem here with my app Roboyard on GitHub: https://stackoverflow.com/q/59130438/1069083 Maybe you find similarities there – rubo77 Jan 29 '20 at 10:09

6 Answers6

19

As Rajen Raiyarela said, go to File->Project Structure->Project->Android Gradle Plugin Version and downgrade it from 3.5.2 to 3.5.1.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
Laila Campos
  • 801
  • 1
  • 8
  • 21
8

Set project dependencies to:

classpath 'com.android.tools.build:gradle:3.5.3'

or latest one.

Note: by doing this, my problem has been resolved.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
  • My problem with gradle 3.5.2 has been resolved in 3.5.3 too, but be aware: I get the warning ` Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.` – rubo77 Feb 02 '20 at 18:38
2

This issue is happening because of duplicate dependencies.
Check for multiple dependencies in the Gradle app.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
  • Correct, this is the issue. There will be duplicate dependencies in your gradle files – MariusB Nov 18 '19 at 11:06
  • 1
    @Srinivasan, if there were duplicates, then it should have been resolved by either exclude or pickfirst in packagingOptions, but it issue with the Gradle plugin only. I m yet to do verify more precisely and create a sample app to regenerate the issue for adding a request in bugtracker for android studio. – Rajen Raiyarela Nov 20 '19 at 12:58
1

Either package it once or not at all:

android {
    packagingOptions {
        pickFirst "META-INF/MANIFEST.MF"
        // exclude "META-INF/MANIFEST.MF"
    }
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

as @rubo77 says and after my confirmation:

  • Latest solution
    • Upgrade gradle version
      • eg:
        • from 3.5.2 to 3.5.3
        • from 3.5.2 to 3.5.4
  • Obsolete solution:
    • downgrade from 3.5.2 to 3.5.1

my choice is : upgrade from 3.5.2 to 3.5.4

build.gradle:

    dependencies {
//        classpath 'com.android.tools.build:gradle:3.5.2'
//        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.android.tools.build:gradle:3.5.4'
    }

gradle 3.5.4

crifan
  • 12,947
  • 1
  • 71
  • 56
0

I was facing the same issue in Android Studio Giraffe,

I delete Build folder and rebuild will fix the issue for me.

Go to project view -> Build

Android Studio

Arpit Patel
  • 7,212
  • 5
  • 56
  • 67