当前位置: 首页 > 面试题库 >

java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法在AndroidStudio 3.0中合并dex

澹台星光
2023-03-14
问题内容

这是我的应用程序级别gradle文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.0'
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        multiDexEnabled true
        applicationId 'com.example.test'
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    productFlavors {
    }
    dexOptions {
        incremental true
    }
}

dependencies {
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    compile 'commons-io:commons-io:1.3.2'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.facebook.stetho:stetho:1.5.0'
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
}

编译项目时出现的完整错误是:

错误:任务’:app:transformDexArchiveWithExternalLibsDexMergerForDebug’的执行失败。

java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex

完整的错误如下:

    Executing tasks: [:app:assembleDebug]

AGPBI: {"kind":"warning","text":"The `android.dexOptions.incremental` property is deprecated and it has no effect on the build process.","sources":[{},{}]}
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
:app:buildInfoDebugLoader
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:checkDebugManifest UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:createDebugCompatibleScreenManifests UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:splitsDiscoveryTaskDebug UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources
:app:javaPreCompileDebug UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:packageInstantRunResourcesDebug UP-TO-DATE
:app:checkManifestChangesDebug
:app:extractTryWithResourcesSupportJarDebug UP-TO-DATE
:app:transformClassesWithStackFramesFixerForDebug UP-TO-DATE
:app:transformClassesWithDesugarForDebug UP-TO-DATE
:app:transformClassesWithExtractJarsForDebug UP-TO-DATE
:app:transformClassesWithInstantRunVerifierForDebug UP-TO-DATE
:app:transformClassesWithDependencyCheckerForDebug UP-TO-DATE
:app:compileDebugNdk NO-SOURCE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes NO-SOURCE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:transformNativeLibsAndResourcesWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:transformClassesWithInstantRunForDebug UP-TO-DATE
:app:transformClassesEnhancedWithInstantReloadDexForDebug UP-TO-DATE
:app:incrementalDebugTasks UP-TO-DATE
:app:preColdswapDebug
:app:fastDeployDebugExtractor UP-TO-DATE
:app:generateDebugInstantRunAppInfo UP-TO-DATE
:app:transformClassesWithInstantRunSlicerForDebug UP-TO-DATE
:app:transformClassesWithDexBuilderForDebug UP-TO-DATE
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
:app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> 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 2s

39 actionable tasks: 5 executed, 34 up-to-date

问题答案:

通过build.gradle您的应用模块启用Multidex

multiDexEnabled true

与以下相同-

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.xx.xxx"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true //Add this
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

然后按照以下步骤操作-

  1. Build菜单->按Clean Project按钮。
  2. 任务完成后,请Rebuild ProjectBuild菜单中按按钮。
  3. 从菜单 File -> Invalidate cashes / Restart

compile是现在已经过时,所以最好使用implementationapi



 类似资料:
  • 错误:任务“:app:TransformDexArchiveWithExternalLibsDexMergerForDebug”执行失败。 java.lang.RuntimeException:com.android.builder.dexing.DexArchivEmergerException:无法合并dex 我尝试了以下帖子推荐的每一个解决方案: 后1 职位2 这是我的应用程序Gradle:

  • 应用程序分级:

  • 任务“:app:TransformDexArchiveWithExternAllibsDexMergerForDebug”执行失败 任务:cordovalib:compiledebubgshaders最新任务:cordovalib:generatedebugassets最新任务:cordovalib:packagedebugassets最新任务:app:mergedebugassets最新任务:a

  • 我知道合并排序算法的基本概念,但是当涉及到通过递归实现它时,我很难理解它是如何工作的。据我所知,合并排序函数将我们当前的数组分成两半,并使用递归我们一直这样做,直到每边只剩下一个元素。 如果我们的数组是{38、27、43、3、9、82、10},那么我们的递归将从使用子数组(原始数组的左侧)调用自身开始,并每次重复该过程,将数组减半并存储最左侧,直到达到1个元素: 然后在我们的第二个子例程中,我们继

  • 在Unity中生成APK时显示此错误: CommandInvokationFailure:无法合并android清单。C:/program files/java/jdk1.8.0_221\bin\java.exe-xmx4096m-dcom.android.sdkmanager.toolsdir=“C:/users/pc/appdata/local/android/android-sdk\tool

  • 应用程序构建: 任何帮助都将不胜感激,因为这个项目即将到期!