Ferran Maylinch
Ferran Maylinch

Reputation: 11529

Getting duplicate entry: META-INF/LICENSE with Android Studio 3.0

When trying to run my Android app (after I updated Android Studio to 3.0 and updated some libs as needed), I get:

Error:Execution failed for task ':MyApp:transformClassesWithStackFramesFixerForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.utils.FileCache$FileCreatorException: java.util.zip.ZipException: duplicate entry: META-INF/LICENSE

I already excluded that META-INF/LICENSE file successfully some time ago using solutions from here but since I updated to Android Studio 3.0 I get that error and I don't know how to fix it.

Do you know how I can exclude that file or get rid of this error?

My gradle file is as follows:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    mavenLocal()
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

allprojects {
    repositories {
        google()
    }
}

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        javaMaxHeapSize "2g"
    }

    defaultConfig {
        versionCode 15040300
        versionName "4.3.0"
        minSdkVersion 15
        targetSdkVersion 26
        multiDexEnabled true
    }

    // http://stackoverflow.com/a/21000452/1121497
    packagingOptions {
        pickFirst 'META-INF/*'
    }

    final Properties signingProps = new Properties()
    final File signingFile = file("signing.properties")
    if (!signingFile.exists()) {
        throw new RuntimeException("You need your signing properties in a git-ignored file: " + signingFile.getAbsolutePath())
    }
    signingProps.load(new FileInputStream(file(signingFile)))

    signingConfigs {
        release {
            storeFile file(signingProps['storeFile'])
            storePassword signingProps['storePassword']
            keyAlias signingProps['keyAlias']
            keyPassword signingProps['keyPassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

dependencies {

    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:mediarouter-v7:26.1.0'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'

    compile 'com.android.support:multidex:1.0.2'

    compile 'com.google.android.gms:play-services-maps:11.4.2'
    compile 'com.google.android.gms:play-services-analytics:11.4.2'
    compile 'com.google.android.gms:play-services-gcm:11.4.2'
    compile 'com.google.firebase:firebase-appindexing:11.4.2'
    compile 'com.google.firebase:firebase-core:11.4.2'

    compile 'commons-codec:commons-codec:1.9'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.github.chrisbanes.photoview:library:1.2.2'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'info.hoang8f:android-segmented:1.0.5'
    compile 'com.facebook.android:facebook-android-sdk:4.27.0'
    compile 'com.facebook.android:notifications:1.0.2'
    compile 'io.card:android-sdk:5.4.2'
    compile 'me.dm7.barcodescanner:zxing:1.9'
    compile 'com.google.android.exoplayer:exoplayer:r2.2.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.0'

    compile fileTree(dir: '../libs', include: '*.jar')

    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }
}

apply plugin: 'com.google.gms.google-services'

Upvotes: 2

Views: 5286

Answers (2)

Ferran Maylinch
Ferran Maylinch

Reputation: 11529

Although I don't know what was happening exactly, here's what I did to fix the problem.

In my jar files, there was one that included multiple license files named LICENSE, LICENSE_1 and LICENSE_2. It looks like they were mistaken for the same file, for some reason.

I just removed all the LICENSE_* files, leaving only LICENSE, and the problem was gone.

Note: The jar was in the files loaded using compile fileTree(dir: '../libs', include: '*.jar')

See also here about excluding files.

Upvotes: 2

Liem Vo
Liem Vo

Reputation: 5329

Try with

packagingOptions {
        pickFirst "anyFileWillDo"
        exclude "/META-INF/**"
 }

Upvotes: -1

Related Questions