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

标签 java android android-studio

我正在尝试构建一个可访问 Spotify 公共(public) API 的应用程序模型,这些是我迄今为止使该应用程序的服务和功能正常运行所需要的。 gradle 同步本身很好,但是当我尝试构建项目时,我遇到了这个问题:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我尝试过的事情:

  1. 从菜单清理并重建项目
  2. 在 gradle 中启用 multidex

multiDexEnabled true

  • 确保不同的依赖项不会在 gradle 中重复
  • 我在 MacOS Sierra 10.12.6 上的 Android Studio 3 上运行。

    这是我的等级:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        buildToolsVersion '26.0.2'
    
        defaultConfig {
            applicationId "com.example.mostags.trial5"
            minSdkVersion 25
            targetSdkVersion 26
            versionCode 1
            versionName "1.2"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        sourceSets {
            main {
                java.srcDirs = ['src/main/java', 'src/main/java/com.example.mostags.trial5/methods']
            }
        }
    }
    
    repositories {
        google()
    
        jcenter()
        mavenCentral()
        flatDir {
            dirs 'libs'
        }
        maven { url 'https://github.com/thelinmichael/spotify-web-api-java' }
    }
    
    android {
        configurations.all {
            resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
            resolutionStrategy.force 'com.google.android.gms:play-services:11.2.2'
        }
    }
    
    
    dependencies {
        compile 'com.android.support:multidex:1.0.2'
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
    
        compile('com.jayway.jsonpath:json-path:2.0.0') {
            exclude group: 'net.minidev', module: 'asm'
        }
    
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        testImplementation 'junit:junit:4.12'
    
    
        compile('com.amazonaws:aws-android-sdk-mobile-client:2.6.7@aar') { transitive = true; }
        compile('com.amazonaws:aws-android-sdk-auth-userpools:2.6.+@aar') { transitive = true; }
        compile('com.amazonaws:aws-android-sdk-auth-ui:2.6.+@aar') { transitive = true; }
    
        compile 'net.sf.json-lib:json-lib:2.4:jdk15'
    
        compile 'com.google.guava:guava:23.6-android'
        compile 'com.google.protobuf:protobuf-java:3.5.1'
        compile 'com.google.protobuf:protobuf-lite:3.0.1'
        compile 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
    
        compile('se.michaelthelin.spotify:spotify-web-api-java:1.5.0') {
            exclude group: "commons-beanutils", module: "commons-beanutils"
    
        }
        compile 'commons-beanutils:commons-beanutils:20030211.134440'
        compile 'commons-codec:commons-codec:1.11'
    
        compile 'org.apache.httpcomponents:httpcore:4.4.8'
        compile 'org.apache.httpcomponents:httpclient:4.5.4'
    
        android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true;
    
        compile fileTree(include: ['*.jar'], dir: 'libs')
    
        //these two lines are added
        compile 'com.squareup.retrofit2:retrofit:2.3.0'
        compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    
        // This library handles authentication and authorization
        compile 'com.spotify.android:auth:1.0.0-alpha'
    
    }

    最佳答案

    试试这个

    multiDexEnabled = true
    

    关于java.lang.RuntimeException : com. andoid.builder.dexing.DexArchiveMergerException 无法合并 dex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48326150/

    相关文章:

    javascript - AJAX 调用未将数据发送到 Controller 方法

    android - 找不到方法minifyEnabled()

    android - 使用 appcompat-v7 更改 Actionbar 中的后退箭头图像

    缺少 Android Studio 文件选项卡

    java - 安卓字验证

    java - 将对象的信息传递给另一个 Activity

    android-studio - 使用 AdMob 公开出价的 FAN Interstital 不起作用

    java - 在扩展父类(super class)功能的同时屏蔽它

    java - 简单的立方体纹理不显示

    java - 使用 Java 杀死进程