Сборка проекта Cordova Android приводит к ошибке «com.android.builder.dexing.DexArchiveMergerException: невозможно объединить dex»

Я буквально понятия не имею, что происходит ... Я даже не знаю, с чего начать ...

Кордова - это версия 8.1.2 Gradle - это версия 4.10.2 Информация о версии Android Studio выглядит следующим образом: Версия 3.2 Сборка № AI-181.5540.7.32.5014246, построена 17 сентября 2018 г. JRE: 1.8.0_152-выпуск-1136-b06 x86_64 JVM: 64-разрядная серверная виртуальная машина OpenJDK от JetBrains s.r.o macOS 10.14

Так что, насколько я знаю, все настолько современно, насколько это возможно.

Я удалил и перестроил платформу 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/[email protected]" 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/[email protected]" 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/[email protected]" 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/[email protected]" width = "120" />
        <icon height = "180" platform = "ios" src = "www/res/icon/ios/[email protected]" 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/[email protected]" 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/[email protected]" 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/[email protected]" width = "58" />
        <icon height = "87" platform = "ios" src = "www/res/icon/ios/[email protected]" 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>

Любая помощь будет принята с благодарностью. Я с радостью предоставлю любую дополнительную информацию, которая может вам понадобиться.

0
0
1 200
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Ошибка com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex часто возникает из-за того, что приложение содержит достаточное количество собственных библиотек и подключаемых модулей Android, превышающее ограничение в 65 536 методов для одного файла DEX (см. multidex в Android). В вашем проекте есть несколько плагинов Cordova, так что этого может быть достаточно, чтобы опрокинуть его.

Решение состоит в том, чтобы включить multidex в вашем проекте, чтобы позволить нескольким файлам DEX преодолеть этот предел, как описано здесь. Самый простой способ сделать это в проекте Cordova - добавить плагин, такой как кордова-мультидекс, который добавит необходимую конфигурацию в Gradle и файлы манифеста в собственном проекте Android.

Мне также пришлось установить плагин cordova-android-support-gradle-release, чтобы все работало. После установки плагина «cordova-multidex» у меня возникла ошибка «: app: transformClassesWithMultidexlistForDebug FAILED». После некоторого исследования я нашел плагин cordova-android-support-gradle-release и попробовал его. Теперь я могу успешно строить. Спасибо!

Laurence MacNeill 10.10.2018 21:50

Другие вопросы по теме