簡體   English   中英

在Android Studio中構建APK時出現DuplicateFileException

[英]DuplicateFileException while building the apk in Android Studio

我在Windows 8上使用Android Studio 2.3.2,並且在構建應用程序時發生錯誤。 首先,在啟動IDE的gradle構建過程中,出現以下警告:

Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is 
ignored for debug as it may be conflicting with the internal version 
provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is 
ignored for release as it may be conflicting with the internal version 
provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is 
ignored for debugAndroidTest as it may be conflicting with the internal 
version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is 
ignored for debug as it may be conflicting with the internal version 
provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is 
ignored for release as it may be conflicting with the internal version 
provided by Android.

然后在apk生成期間有2條警告和此錯誤:

Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is 
ignored for release as it may be conflicting with the internal version 
provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is 
ignored for debug as it may be conflicting with the internal version 
provided by Android.

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/LICENSE
File1: C:\Users\giorgia\.gradle\caches\modules-2\files-
2.1\com.fasterxml.jackson.core\jackson-
core\2.2.3\1a0113da2cab5f4c216b4e5e7c1dbfaa67087e14\jackson-core-2.2.3.jar
File2: C:\Users\giorgia\.gradle\caches\modules-2\files-
2.1\com.fasterxml.jackson.core\jackson-
annotations\2.2.3\527fece4f23a457070a36c371a26d6c0208e1c3\jackson-
annotations-2.2.3.jar
File3: C:\Users\giorgia\.gradle\caches\modules-2\files- 2.1\org.apache.httpcomponents\httpmime\4.3.6\cf8bacbf0d476c7f2221f861269365b664
47f7ec\httpmime-4.3.6.jar
File4: C:\Users\giorgia\.gradle\caches\modules-2\files-
2.1\com.fasterxml.jackson.core\jackson-
databind\2.2.3\3ae380888029daefb91d3ecdca3a37d8cb92bc9\jackson-databind-
2.2.3.jar
File5: C:\Users\giorgia\.gradle\caches\modules-2\files- 2.1\org.apache.httpcomponents\httpcore\4.4.3\e876a79d561e5c6207b78d347e198c8c45
31a5e5\httpcore-4.4.3.jar

在buildToolsVersion之后,您需要在“應用” build.gradle文件中使用packaginOptions:

packagingOptions {
    exclude 'META-INF/LICENSE'
}

嘗試將其添加到buiild.gradle中

這是因為您沒有排除存在於多個依賴項中的META-INF/LICENSE文件

packagingOptions {
    exclude 'META-INF/NOTICE' // will not include NOTICE file
    exclude 'META-INF/LICENSE' // will not include LICENSE file
    // as noted by @Vishnuvathsan you may also need to include
    // variations on the file name. It depends on your dependencies.
    // Some other common variations on notice and license file names
    exclude 'META-INF/notice'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license'
    exclude 'META-INF/license.txt'
}

啟用multiDex

defaultConfig {

             // Enabling multidex support.
             multiDexEnabled true
         }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM