【问题标题】:How to solve a Duplicate file exception in android?如何解决android中的重复文件异常?
【发布时间】:2017-01-25 07:03:51
【问题描述】:

我正在尝试使用Firebase 制作聊天应用程序。代码似乎很好,但在尝试运行项目时遇到了一个奇怪的错误。

这是错误:

Error:FAILURE: Build failed with an exception.
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: C:\Users\Aadesh\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.2.2\285cb9c666f0f0f3dd8a1be04e1f457eb7b15113\jackson-annotations-2.2.2.jar
File2: C:\Users\Aadesh\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.2.2\3c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
File3: C:\Users\Aadesh\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar


* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

可能是什么问题,我该如何解决?

Gradle 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "com.example.aadesh.chatnow"
    minSdkVersion 17
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.volley:volley:1.0.0'
testCompile 'junit:junit:4.12'
compile 'com.firebase:firebase-client-android:2.5.2'
}
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 您是否使用 --debug 和/或 --stacktrace 运行过?
  • 是的,它给出了同样的错误
  • 您可能在不同的 gradle 文件中重复这些库。它们不止一次发生。
  • 我已经添加了我的 gradle 文件。我检查了它,但我找不到任何重复。

标签: android json firebase-realtime-database


【解决方案1】:

你应该添加:

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

到您的build.gradle 文件。这将在合并库时跳过这些文件。

【讨论】:

  • 如果我们跳过这些文件会对应用产生什么影响?
  • 无,因为这些文件不包含任何代码。这些只是分发的许可和通知。
  • 多么简单的解决方案。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-25
  • 2019-07-11
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
  • 1970-01-01
相关资源
最近更新 更多