简体   繁体   English

尝试导入2个jar文件时,Android Studio出现DuplicateFileException

[英]DuplicateFileException with Android Studio when trying to import 2 jar files

I am trying to import two jar files to my Android Studio Project. 我正在尝试将两个jar文件导入到我的Android Studio项目中。 But when i try to run the code. 但是当我尝试运行代码时。 I get the following Error. 我收到以下错误。

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
 > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate
files copied in APK META-INF/ECLIPSE_.RSA

File1: A:\Uni-mora-sem4\IOT\Project\ClientApp\AndroidClientV2\app\libs
\org.eclipse.paho.android.service-1.0.2.jar

File2: A:\Uni-mora-sem4\IOT\Project\ClientApp\AndroidClientV2\app\libs\org.eclipse.paho.client.mqttv3-1.0.2.jar

Gradle File is as Follows......... Gradle File如下.........

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "iot.dulanga.com.androidclientv2"
        minSdkVersion 13
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    maven {
        url "https://repo.eclipse.org/content/repositories/paho-releases/"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile files('libs/org.eclipse.paho.android.service-1.0.2.jar')
    compile files('libs/org.eclipse.paho.client.mqttv3-1.0.2.jar')

}

Any ideas why I get this error ?? 任何想法为什么我会收到此错误?

This is because both the jar s are containing META-INF/ECLIPSE_.RSA and thus while packing the apk , duplication is arising. 这是因为两个jar都包含META-INF/ECLIPSE_.RSA ,因此在打包apk时会出现重复。

So try to add this in the app's build.gradle : 因此,尝试将其添加到应用程序的build.gradle

android {
   packagingOptions {
      exclude 'META-INF/ECLIPSE_.RSA'
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM