简体   繁体   English

在将模块添加到Android应用程序时获取DuplicateFileException

[英]Getting a DuplicateFileException when adding a module to my Android app

I am trying to add the Paho MQTT service (and client) to my Android app, but I am running into a com.android.builder.packaging.DuplicateFileException runtime exception, when running my app. 我试图将Paho MQTT服务(和客户端)添加到我的Android应用程序中,但是运行我的应用程序时,我遇到了com.android.builder.packaging.DuplicateFileException运行时异常。

It appears to me that everything is setup right, and when I clean/build, I get no errors at all. 在我看来 ,这一切都是建立正确的,当我清理/建造,我没有错误可言。

My app build.gradle file looks like: 我的应用程序 build.gradle文件如下所示:

dependencies {
    compile fileTree(dir: '../org.eclipse.paho.android/service/libs', excludes: ["org.eclipse.paho.client.mqttv3-1.1.0.jar"], include: '')
    compile fileTree(include: ['*.jar'], dir: 'libs', excludes: ["*org.eclipse.paho.client.mqttv3-1.1.0.jar"])
    compile (project(':org.eclipse.paho.android.service')){
        // exclude module: "org.eclipse.paho.client.mqttv3"
        transitive=true
    }

    // Uncommenting the below (when commenting out the above) WORKS.
    //   However, I need to be able to alter the source, to I do need to be able 
    //   to import the Paho MQTT service as a module to my app.
    // compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
    // compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

    ...

However, when I run, I receive a DuplicateFileException exception: 但是,当我运行时,我收到DuplicateFileException异常:

* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/eclipse/paho/client/mqttv3/internal/nls/messages_zh_TW.properties
    File1: /Users/me/.gradle/caches/modules-2/files-2.1/org.eclipse.paho/org.eclipse.paho.client.mqttv3/1.1.0/89d827ffa47c241f2627421ef1d6c7a8c207a341/org.eclipse.paho.client.mqttv3-1.1.0.jar
    File2: /Users/me/myapp/code/myapp-android/org.eclipse.paho.android.service/build/intermediates/bundles/default/classes.jar

My file hierarchy looks like: 我的文件层次结构如下:

在此处输入图片说明

which appears ok to me. 对我来说似乎还可以

Does anyone have any pointers on how to resolve this? 有人对如何解决这个问题有任何指示吗? The error claims that org.eclipse.paho.client.mqttv3-1.1.0.jar is clashing with classes.jar , but my gradle file explicitly excludes the compiling of org.eclipse.paho.client.mqttv3-1.1.0.jar (or so I think it does). 该错误声称org.eclipse.paho.client.mqttv3-1.1.0.jarclasses.jar冲突,但是我的gradle文件明确排除了org.eclipse.paho.client.mqttv3-1.1.0.jar的编译(或者,我认为是的)。

I'm at a loss here; 我在这里不知所措; any pointers are welcomed. 任何指针都欢迎。

This happens because two of your dependencies are using Eclipse Paho MQTT library. 发生这种情况是因为您的两个依赖项正在使用Eclipse Paho MQTT库。

Following should fix the issue 以下应该解决问题

Add following to your app level gradle file 将以下内容添加到您的应用级gradle文件中

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

compile("one-of-your-dependency:1.0.0"){
    exclude group: 'org.eclipse.paho'
}

暂无
暂无

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

相关问题 使用RealmSearchView时出现Android DuplicateFileException - Android DuplicateFileException when using RealmSearchView 尝试导入2个jar文件时,Android Studio出现DuplicateFileException - DuplicateFileException with Android Studio when trying to import 2 jar files 将外部jar添加到纯Java模块时出现NoClassDefFoundError,这是Android Studio中应用程序模块的依赖项 - NoClassDefFoundError when adding external jar to a pure java module, which is a dependency of the app module in Android Studio 尝试使用平板电脑下载时,我的 android 应用程序不支持设备 - My android app is getting device not supported when trying to download with tablet 在Android Studio中添加新模块时出现java.lang.NoClassDefFoundError:android.support.v4.app.NavUtilsJB错误 - java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB error when adding new module in Android Studio Android:添加可绘制的tabselector时,出现不想要的apx。 标签上的5px填充 - Android: When adding a drawable tabselector I am getting an unwanted apx. 5px padding on my tabs 添加 OnclickListener 后,我的 Android 应用程序崩溃 - My Android App crashes after adding an OnclickListener android studio中的com.android.builder.packaging.DuplicateFileException - com.android.builder.packaging.DuplicateFileException in android studio 添加 RecyclerView Layoutmanager 时我的应用程序停止 - My app stopped when adding a RecyclerView Layoutmanager 使用wasItTouched事件让我的Android应用程序振动 - Getting my Android App to vibrate with a wasItTouched event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM