0

I'm new to Android and I'm trying to work though this tutorial (just the Room database part): here.

When I execute my app I get the following error:

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

This issue seemed to show up after I followed this to fix another error (regarding the schema export directory for Room). I've tried to follow this post's advice about fixing this issue by using multiDexEnabled true and doing clean/re-build but it hasn't worked.

Any advice would be appreciated. This is my first post here so if I've done anything wrong please let me know.

Project 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
}

App 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'
}
David
  • 1

2 Answers2

0

Update buildToolsVersion and supportLibVersion to the latest in your code below.

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

}

And then Clean and Rebuild Project to see if it works.

Fio
  • 3,088
  • 2
  • 13
  • 23
0

I found a solution. Replacing:

"android.arch.persistence.room:runtime:1.0.0-alpha1" 

and

"android.arch.persistence.room:compiler:1.0.0-alpha1"

with

"android.arch.persistence.room:runtime:1.0.0"

and

"android.arch.persistence.room:compiler:1.0.0"
David
  • 1