[英]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.jar
与classes.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.