Android Studio: Duplicate files copied in APK META-INF/DEPENDENCIES when compile

前端 未结 6 1619
野的像风
野的像风 2020-11-29 04:56

I exported my project from Eclipse and imported to Android Studio using the instructions in this link: http://developer.android.com/sdk/installing/migrate.html

When

相关标签:
6条回答
  • 2020-11-29 05:30

    While Scott Barta's answer is correct, is lacks a simple and common solution: just add

    android {
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }
    }
    

    to your build.gradle to ignore those duplicates.

    0 讨论(0)
  • 2020-11-29 05:33

    dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:design:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.google.android.gms:play-services-ads:10.2.1' implementation 'com.android.support:support-annotations:25.0.1' testImplementation 'junit:junit:4.12'

    **// select only one in two line below**  implementation ‘package’    //implementation project(‘:package’)
    

    }

    // good luck

    0 讨论(0)
  • 2020-11-29 05:40

    The easiest way I've found to resolve this problem is to use a wildcard, so you don't find yourself having to manually declare each file in conflict.

    packagingOptions {
        pickFirst  '**'
    }
    
    0 讨论(0)
  • 2020-11-29 05:45

    The simplest solution is to add

     packagingOptions {
        pickFirst  'META-INF/*'
    }
    

    to your build.gradle in android section

    0 讨论(0)
  • 2020-11-29 05:49

    In Android Gradle builds, you're not permitted to include the same file with the same path more than once in the output. In your build, there were two META-INF/DEPENDENCIES files coming from different places. Since you don't need this file at all in your application, the simplest thing to do is to tell the build system to ignore it altogether, which is what this exclude directive does.

    There's also a pickFirst directive to tell the build system to keep one of the copies; there's a tiny amount of detail on that in Android Gradle plugin 0.7.0: "duplicate files during packaging of APK".

    Android builds in Gradle are rather strict about duplicate files, which can make life difficult. There's a similar problem if you include the same Java class more than once, where you get the "Multiple dex files define" error (see Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat) for a typical example).

    Other build systems are more lenient. It's typical in Java that if you include the same class more than once in a classpath, for example, the first copy it sees is the one that's used; duplicates after that are ignored. This is in most cases easier to deal with, but it has a couple problems. The biggest one is that there can be subtle errors if multiple different versions of a file creep into the build without you knowing -- it can be difficult to figure out what's going on. When you do figure it out, you can usually solve it by juggling the order in which things are included to make sure the one you want makes it to the final output, but in very complex builds, this can be difficult to achieve, and it can happen that doing seemingly unrelated things like including new libraries in your project can upset the ordering and lead to a lot of woe.

    For that reason, Gradle has the philosophy of not relying on ordering of things to determine "winners" in the game of resolving duplicates, and it forces the developer to make all dependencies explicit. Android's implementation of its build system on top of Gradle follows that philosophy.

    0 讨论(0)
  • 2020-11-29 05:56

    In case that anyone having these problem while uploading new .apk to Google Play Store, after updatng Android Studio ;

    click V1 Jar Signature not Full Apk Signature while Generating new Apk with old Keystore

    0 讨论(0)
提交回复
热议问题