android - 无法合并dex-Gradle 3.0.0

标签 android gradle dex android-room

我是Android的新手,并且正在尝试通过本教程(仅Room数据库部分):here进行工作。

当我执行我的应用程序时,出现以下错误:

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



我按照this修复另一个错误(关于Room的模式导出目录)后,似乎出现了此问题。我尝试遵循this post's有关通过使用multiDexEnabled true并进行清理/重新构建来解决此问题的建议,但未成功。

任何意见,将不胜感激。这是我在这里的第一篇文章,因此,如果我做错了任何事情,请告诉我。

项目gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

ext {
    buildToolsVersion = "25.0.2"
    supportLibVersion = "25.3.1"
    archRoomVersion = "1.0.0-alpha1"
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com' } //needed for Room

    }
}

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

应用程式Gradle:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.myname.room_example"
        minSdkVersion 21
        targetSdkVersion 26
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] // Room schema
            }
        }

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:multidex:1.0.2'

    implementation "android.arch.persistence.room:runtime:1.0.0-alpha1"
    annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
    implementation 'com.android.support:support-annotations:27.0.0'
}

最佳答案

在下面的代码中将buildToolsVersionsupportLibVersion更新为最新版本。

ext {
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
archRoomVersion = "1.0.0-alpha1"

}

然后清理并重建项目以查看其是否有效。

关于android - 无法合并dex-Gradle 3.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47427554/

相关文章:

android - 如何在 Android 中流式传输 RTMP 直播视频

java - 改造 POST 请求 response.isSuccessful() 返回 false

java - 我可以使用 JavaFX 向我的程序添加更多开始菜单项吗?

file - Jacoco Gradle jacocoTestReport 任务失败生成报告时出错 - 是一个目录

java - 验证者拒绝类 - Kotlin

java - 当我将 .jar 文件包含到我的 android 项目中时出现 Dex 错误

android - 使用 gradle 构建时出现 dexDebug 错误

android - 使用改造缓存特定响应

android - 有没有办法使用 Scala 将两个或多个 .dex 文件合并到一个 .dex 文件中?

android - jetpack 内的动画组成绘制范围