java - com.android.builder.dexing.DexArchiveMergerException : Error while merging dex archives:

标签 java android android-studio kotlin javacompiler

我无法编译我的项目,场景是我使用 Android Studio 的“将 Java 文件转换为 Kotlin 文件”将我的 Activity 之一转换为 kotlin,并修复了未正确转换的代码的所有错误。

Java 编译器日志:

Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:


com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:



com.android.tools.r8.CompilationFailedException: Compilation failed to complete



com.android.tools.r8.utils.AbortException: Error: null, Cannot fit requested classes in a single dex file (# methods: 110666 > 65536 ; # fields: 67264 > 65536)


build.gradle(应用程序)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    defaultConfig {
        versionName "2.2.4"
        versionCode 13

        minSdkVersion 16
        targetSdkVersion 27

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix ".d.5"
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "server"

    productFlavors {
        prod {
            applicationId "com.test.test"
            dimension "server"

            buildConfigField "String", "SERVER_HOST", "\"http://www.test.com\""
        }

        dev {
            applicationId "dev.test.test"
            versionNameSuffix ".dev"
            dimension "server"

            buildConfigField "String", "SERVER_HOST", "\"http://localhost/test\""
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true
    }

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.schibstedspain.android:leku:6.0.0'

    implementation 'com.github.sparklit:adbutler-android-sdk:1.0'
    implementation 'com.j256.ormlite:ormlite-core:5.0'
    implementation 'com.j256.ormlite:ormlite-android:5.0'
    implementation 'com.squareup.okhttp:okhttp:2.4.0'
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.cardview:cardview:1.0.0-beta01'
    implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
    implementation 'com.google.android.material:material:1.0.0-beta01'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.facebook.fresco:fresco:1.9.0'
    implementation 'com.jakewharton.timber:timber:4.7.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    testImplementation 'junit:junit:4.12'
    def nav_version = "1.0.0-alpha09"
    implementation "android.arch.navigation:navigation-fragment:$nav_version"
    // use -ktx for Kotlin
    implementation "android.arch.navigation:navigation-ui:$nav_version"
    // use -ktx for Kotlin

    implementation 'pub.devrel:easypermissions:1.1.1'
    implementation 'devlight.io:navigationtabbar:1.2.5'
}

configurations.all {
    exclude group: 'com.google.guava', module: 'listenablefuture'
}

apply plugin: 'com.google.gms.google-services'

repositories {
    mavenCentral()
}


build.gradle(项目)

buildscript {
    ext.kotlin_version = '1.3.11'
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'io.fabric.tools:gradle:1.27.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url "https://maven.google.com" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

最佳答案

我的错(现已修复)
将其添加到defaultConfig中的build.gradle(应用程序)

multiDexEnabled true

build.gradle(应用程序)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    defaultConfig {
        versionName "2.2.4"
        versionCode 13

        minSdkVersion 16
        targetSdkVersion 27

        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix ".d.5"
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "server"

    productFlavors {
        prod {
            applicationId "com.tfwm.lighting"
            dimension "server"

            buildConfigField "String", "SERVER_HOST", "\"http://www.test.com\""
        }

        dev {
            applicationId "dev.tfwm.lighting"
            versionNameSuffix ".dev"
            dimension "server"

            buildConfigField "String", "SERVER_HOST", "\"http://localhost/test\""
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true
    }

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.schibstedspain.android:leku:6.0.0'

    implementation 'com.github.sparklit:adbutler-android-sdk:1.0'
    implementation 'com.j256.ormlite:ormlite-core:5.0'
    implementation 'com.j256.ormlite:ormlite-android:5.0'
    implementation 'com.squareup.okhttp:okhttp:2.4.0'
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.cardview:cardview:1.0.0-beta01'
    implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
    implementation 'com.google.android.material:material:1.0.0-beta01'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.facebook.fresco:fresco:1.9.0'
    implementation 'com.jakewharton.timber:timber:4.7.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    testImplementation 'junit:junit:4.12'
    def nav_version = "1.0.0-alpha09"
    implementation "android.arch.navigation:navigation-fragment:$nav_version"
    // use -ktx for Kotlin
    implementation "android.arch.navigation:navigation-ui:$nav_version"
    // use -ktx for Kotlin

    implementation 'pub.devrel:easypermissions:1.1.1'
    implementation 'devlight.io:navigationtabbar:1.2.5'
}

configurations.all {
    // this is a workaround for the issue:
    // https://stackoverflow.com/questions/52521302/how-to-solve-program-type-already-present-com-google-common-util-concurrent-lis
    exclude group: 'com.google.guava', module: 'listenablefuture'
}

apply plugin: 'com.google.gms.google-services'

repositories {
    mavenCentral()
}

java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex in Android Studio 3.0 [closed]

Also solution is NOT REQUIRED if your minSdkVersion is set to 21 and above

关于java - com.android.builder.dexing.DexArchiveMergerException : Error while merging dex archives:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54797813/

相关文章:

java - 从另一种方法获取字符串?

java - Maven 项目管理

android - 从启动的 Activity 返回后 RecyclerView 布局损坏

java - Android 应用程序在尝试连接 SQLite 数据库时崩溃

android - 我应该在Android Studio中使用哪个appcompat版本?

android - 如何在android中覆盖双击电源按钮或音量按钮?

java - 如何重命名现有文件

android - flutter 图像自动幻灯片/轮播,给定随机间隔

java - FragmentManager 支持库的不兼容类型

java - 创建自己的数据库类和使用 DBMS 之间的区别