构建Cordova Android项目导致“com.android.builder.dexing.DexArchiveMergerException:无法合并dex”错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了构建Cordova Android项目导致“com.android.builder.dexing.DexArchiveMergerException:无法合并dex”错误相关的知识,希望对你有一定的参考价值。
我几乎不知道发生了什么......我甚至不知道从哪里开始看......
Cordova是版本8.1.2 Gradle是版本4.10.2 android Studio版本信息如下:版本3.2 Build#AI-181.5540.7.32.5014246,建于2018年9月17日JRE:1.8.0_152-release-1136-b06 x86_64 JVM:JetBrains sro macOS 10.14的OpenJDK 64位服务器VM
据我所知,所有事情都是最新的。
我删除并重建了Android平台:
cordova platform rm android
cordova platform add android
cordova build android
这是我输入“cordova build android”后出现的所有内容的全文:
Android Studio project detected
ANDROID_HOME=/Users/<myUserName>/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
studio
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at build_9hmaa6fgshe34pexshtv71mb2.run(/Users/lmacneill/PhoneGap Projects/qConnection/platforms/android/app/build.gradle:144)
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:compileDebugAidl
:CordovaLib:compileDebugRenderscript
:CordovaLib:checkDebugManifest
:CordovaLib:generateDebugBuildConfig
:CordovaLib:prepareLintJar
:CordovaLib:generateDebugResValues
:CordovaLib:generateDebugResources
:CordovaLib:packageDebugResources
:CordovaLib:platformAttrExtractor
:CordovaLib:processDebugManifest
:CordovaLib:javaPreCompileDebug
:CordovaLib:processDebugJavaRes NO-SOURCE
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl
:CordovaLib:packageDebugRenderscript NO-SOURCE
:app:compileDebugRenderscript
:app:checkDebugManifest
:CordovaLib:processDebugResources
:CordovaLib:generateDebugSources
:CordovaLib:compileDebugJavaWithJavacNote: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug
:app:generateDebugBuildConfig
:app:prepareLintJar
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:createDebugCompatibleScreenManifests
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug
:app:processDebugResources
:app:generateDebugSources
:app:javaPreCompileDebug
:app:compileDebugJavaWithJavacNote: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/lmacneill/PhoneGap Projects/qConnection/platforms/android/app/src/main/java/org/apache/cordova/file/AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:app:compileDebugNdk NO-SOURCE
:app:compileDebugSources
:CordovaLib:mergeDebugShaders
:CordovaLib:compileDebugShaders
:CordovaLib:generateDebugAssets
:CordovaLib:mergeDebugAssets
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:transformClassesWithStackFramesFixerForDebug
:app:transformClassesWithDesugarForDebug
:app:transformClassesWithDexBuilderForDebug
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 20s
37 actionable tasks: 37 executed
/Users/lmacneill/PhoneGap Projects/qConnection/platforms/android/gradlew: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/lmacneill/PhoneGap Projects/qConnection/platforms/android/app/src/main/java/org/apache/cordova/file/AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 20s
在第6行是“建立成功”?但后来它失败了......不知道为什么?我的意思是,如果成功了,为什么不止步呢?
更接近底部 - “AssetFileSystem使用未经检查或不安全的操作”事情应该只是一个警告,不应该导致构建失败,但我不确定这是真的,因为它发生在构建失败之前......
但是,就像我之前说过的那样,我几乎没有什么可以开始寻找它来自哪里。我只是不太了解Android知道去哪里...
这是我的config.xml文件:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.myapp" version="1.2.8" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>myApp Name</name>
<description>myApp Description</description>
<author email="my@email" href="http://example.com/myAppLink">My Name</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
<icon density="ldpi" src="www/res/icon/android/drawable-ldpi-icon.png" />
<icon density="mdpi" src="www/res/icon/android/drawable-mdpi-icon.png" />
<icon density="hdpi" src="www/res/icon/android/drawable-hdpi-icon.png" />
<icon density="xhdpi" src="www/res/icon/android/drawable-xhdpi-icon.png" />
<icon density="xxhdpi" src="www/res/icon/android/drawable-xxhdpi-icon.png" />
<icon density="xxxhdpi" src="www/res/icon/android/drawable-xxxhdpi-icon.png" />
<splash density="land-ldpi" src="www/res/screen/android/drawable-land-ldpi-screen.png" />
<splash density="land-mdpi" src="www/res/screen/android/drawable-land-mdpi-screen.png" />
<splash density="land-hdpi" src="www/res/screen/android/drawable-land-hdpi-screen.png" />
<splash density="land-xhdpi" src="www/res/screen/android/drawable-land-xhdpi-screen.png" />
<splash density="land-xxhdpi" src="www/res/screen/android/drawable-land-xxhdpi-screen.png" />
<splash density="land-xxxhdpi" src="www/res/screen/android/drawable-land-xxxhdpi-screen.png" />
<splash density="port-ldpi" src="www/res/screen/android/drawable-port-ldpi-screen.png" />
<splash density="port-mdpi" src="www/res/screen/android/drawable-port-mdpi-screen.png" />
<splash density="port-hdpi" src="www/res/screen/android/drawable-port-hdpi-screen.png" />
<splash density="port-xhdpi" src="www/res/screen/android/drawable-port-xhdpi-screen.png" />
<splash density="port-xxhdpi" src="www/res/screen/android/drawable-port-xxhdpi-screen.png" />
<splash density="port-xxxhdpi" src="www/res/screen/android/drawable-port-xxxhdpi-screen.png" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<icon height="57" platform="ios" src="www/res/icon/ios/icon.png" width="57" />
<icon height="114" platform="ios" src="www/res/icon/ios/icon@2x.png" width="114" />
<icon height="40" platform="ios" src="www/res/icon/ios/icon-40.png" width="40" />
<icon height="80" platform="ios" src="www/res/icon/ios/icon-40@2x.png" width="80" />
<icon height="50" platform="ios" src="www/res/icon/ios/icon-50.png" width="50" />
<icon height="100" platform="ios" src="www/res/icon/ios/icon-50@2x.png" width="100" />
<icon height="60" platform="ios" src="www/res/icon/ios/icon-60.png" width="60" />
<icon height="120" platform="ios" src="www/res/icon/ios/icon-60@2x.png" width="120" />
<icon height="180" platform="ios" src="www/res/icon/ios/icon-60@3x.png" width="180" />
<icon height="72" platform="ios" src="www/res/icon/ios/icon-72.png" width="72" />
<icon height="144" platform="ios" src="www/res/icon/ios/icon-72@2x.png" width="144" />
<icon height="76" platform="ios" src="www/res/icon/ios/icon-76.png" width="76" />
<icon height="152" platform="ios" src="www/res/icon/ios/icon-76@2x.png" width="152" />
<icon height="29" platform="ios" src="www/res/icon/ios/icon-small.png" width="29" />
<icon height="58" platform="ios" src="www/res/icon/ios/icon-small@2x.png" width="58" />
<icon height="87" platform="ios" src="www/res/icon/ios/icon-small@3x.png" width="87" />
<splash height="1136" platform="ios" src="www/res/screen/ios/Default-568h@2x~iphone.png" width="640" />
<splash height="1334" platform="ios" src="www/res/screen/ios/Default-667h.png" width="750" />
<splash height="2208" platform="ios" src="www/res/screen/ios/Default-736h.png" width="1242" />
<splash height="1242" platform="ios" src="www/res/screen/ios/Default-Landscape-736h.png" width="2208" />
<splash height="1536" platform="ios" src="www/res/screen/ios/Default-Landscape@2x~ipad.png" width="2048" />
<splash height="768" platform="ios" src="www/res/screen/ios/Default-Landscape~ipad.png" width="1024" />
<splash height="2048" platform="ios" src="www/res/screen/ios/Default-Portrait@2x~ipad.png" width="1536" />
<splash height="1024" platform="ios" src="www/res/screen/ios/Default-Portrait~ipad.png" width="768" />
<splash height="960" platform="ios" src="www/res/screen/ios/Default@2x~iphone.png" width="640" />
<splash height="480" platform="ios" src="www/res/screen/ios/Default~iphone.png" width="320" />
</platform>
<plugin name="cordova-plugin-file" spec="^6.0.1" />
<plugin name="cordova-plugin-media" spec="^5.0.2" />
<plugin name="cordova-plugin-camera" spec="^4.0.3">
<variable name="CAMERA_USAGE_DESCRIPTION" value="App uses Camera." />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="App does not use Photo Library." />
</plugin>
<plugin name="cordova-plugin-device" spec="^2.0.2" />
<plugin name="cordova-plugin-dialogs" spec="^2.0.1" />
<plugin name="cordova-plugin-inappbrowser" spec="^3.0.0" />
<plugin name="cordova-plugin-network-information" spec="^2.0.1" />
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
<plugin name="mobi.pdf417.Pdf417Scanner" spec="./pdf417-phonegap/Pdf417" />
<engine name="android" spec="^7.1.1" />
<engine name="ios" spec="^4.5.5" />
</widget>
任何帮助都将非常感谢。我很乐意提供您可能需要的更多信息。
错误com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
经常出现,因为一个应用程序包含足够的原生Android库和插件,它超过单个DEX文件的65,536方法限制(请参阅multidex in Android)。您的项目中有一些Cordova插件,因此这可能足以超过限制。
解决方案是在项目中启用multidex以启用多个DEX文件来克服此限制,as described here。在Cordova项目中执行此操作的最简单方法是添加一个插件,例如cordova-multidex,它将向Gradle添加必要的配置并在原生Android项目中添加清单文件。
以上是关于构建Cordova Android项目导致“com.android.builder.dexing.DexArchiveMergerException:无法合并dex”错误的主要内容,如果未能解决你的问题,请参考以下文章
cordova.exec 导致我的 Android 项目出现问题
运行cordova build android时出错(退出代码1)
向 Ionic 4 项目添加 cordova-plugin-firebase-dynamiclinks 导致无法构建