2017-10-01 23 views
5

Próbuję uruchomić mojej aplikacji na moim telefonie, ale podczas build czasu nie powiedzie się z powodu następującego błędu:android - Uruchamianie aplikacji nie powiedzie się z powodu błędu „com.android.builder.dexing.DexArchiveMergerException: Nie można połączyć Dex”

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. 

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

co starałem tak daleko, ale bezskutecznie: -> Clean i odbudowy (nie na odbudowę) -> Usuń ./gradle plik i wszystkie pliki kompilacji projektu i cache, potem cache unieważnienie

Mój projektor t Gradle plik:

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

buildscript { 
    ext.kotlin_version = '1.1.51' 
    repositories { 
     jcenter() 
     google() 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:3.0.0-beta6' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     google() 
     mavenCentral() 
    } 
} 

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

Moja aplikacja Gradle plik:

apply plugin: 'com.android.application' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-kapt' 
apply plugin: 'kotlin-android-extensions' 

def daggerVersion = '2.11' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "26.0.2" 
    defaultConfig { 
     applicationId "com.connectus.connectus" 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    packagingOptions { 
     exclude 'META-INF/INDEX.LIST' 
    } 
} 

kapt { 
    generateStubs = true 
} 

dependencies { 
    /** 
    * Kotlin 
    */ 
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 
    compile 'org.jetbrains.anko:anko-support-v4:0.10.1' 

    /** 
    * Unit testing 
    */ 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.10.19' 
    testCompile 'org.powermock:powermock-module-junit4:1.6.2' 
    testCompile 'org.powermock:powermock-api-mockito:1.6.2' 

    /** 
    * Android views and widgets 
    */ 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support:recyclerview-v7:25.3.1' 
    compile 'com.android.support:cardview-v7:25.3.1' 

    /** 
    * Retrofit 
    */ 
    compile 'com.squareup.retrofit2:retrofit:2.+' 
    compile 'com.squareup.retrofit2:converter-gson:2.+' 
    compile 'com.squareup.retrofit2:adapter-rxjava:2.+' 
    compile 'io.reactivex:rxjava:1.0.4' 
    compile 'io.reactivex:rxandroid:0.24.0' 

    /** 
    * Glide 
    */ 
    compile 'com.github.bumptech.glide:glide:3.7.0' 

    /** 
    * Dagger 2 
    */ 
    kapt "com.google.dagger:dagger-compiler:$daggerVersion" 
    compile "com.google.dagger:dagger:$daggerVersion" 
    provided 'org.glassfish:javax.annotation:10.0-b28' 

    /** 
    * Butterknife for view injection 
    */ 
    compile 'com.jakewharton:butterknife:8.8.1' 
    kapt 'com.jakewharton:butterknife-compiler:8.8.1' 

    /** 
    * GSON 
    */ 
    compile 'com.google.code.gson:gson:2.6.2' 
    compile 'org.powermock:powermock-api-mockito:1.6.2' 

    /** 
    * Facebook SDK 
    */ 
    compile 'com.facebook.android:facebook-login:[4,5)' 

    /** 
    * UI Testing 
    */ 
    androidTestCompile 'com.android.support:support-annotations:25.3.1' 
    androidTestCompile 'junit:junit:4.12' 

    testCompile 'com.google.dexmaker:dexmaker:1.2' 
    testCompile 'com.google.dexmaker:dexmaker-mockito:1.2' 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') { 
     exclude module: 'support-annotations' 
    } 
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') { 
     exclude module: 'support-annotations' 
     exclude module: 'appcompat-v7' 
     exclude module: 'support-v4' 
     exclude module: 'support-v13' 
     exclude module: 'recyclerview-v7' 
     exclude module: 'design' 
    } 
    androidTestCompile('com.android.support.test:runner:0.3') { 
     exclude module: 'support-annotations' 
    } 
    androidTestCompile('com.android.support.test:rules:0.3') { 
     exclude module: 'support-annotations' 
    } 
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
} 

apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-android-extensions' 
repositories { 
    mavenCentral() 
} 

Używam Kotlin i Android Studio 3.0.0 beta 6. Na czym polega problem?

+0

bym unieważnienie pamięci podręcznej i ponowne uruchomienie, a następnie spróbuj ponownie. Jeśli problem nie zostanie rozwiązany, musisz sprawdzić zależności. czasami zależności AAR mają wewnętrzne biblioteki JAR o tej samej nazwie pakietu, a gdy Android Studio chce scalić te pliki JAR, generuje błąd, który jest wyjątkiem scalającym. Szukałbym pewnej biblioteki, która zawiera wewnątrz JAR;) –

+0

Mam taki sam błąd jak OP, ale nieco inny kod, miałem compileSdkVersion ustawioną na 26, a biblioteki com.android.support wciąż na 25.3.1. Uaktualnienie ich do wersji 26.0.2 naprawiło dla mnie błąd dex merge. – Sherlock

Odpowiedz

3

Chociaż nie jestem do końca pewien co do tego, wydaje się, po wykonaniu some digging, że istnieje konflikt wersji między bibliotekami adnotacji zawartych w jetbrainach w pluginach kotlina i gdzie indziej. Można to sprawdzić uruchamiając

gradle :app:assembleDebug --stacktrace

co daje w końcu,

Caused by: com.android.dex.DexException: Multiple dex files define Lorg/intellij/lang/annotations/JdkConstants$PatternFlags; 
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661) 
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616) 
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598) 
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) 
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:198) 
    at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61) 
    ... 1 more 

Rozwiązałem to przez wyłączenie biblioteki adnotacje z Kotlin uzależnienia. (Po tym może być konieczne wyczyszczenie i przebudowanie)

implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") { 
    exclude group: 'org.jetbrains', module: 'annotations' 
} 

To działa dla mnie, ale nie jestem pewien jak dobre jest to rozwiązanie.

+0

Witam Mam dokładnie ten problem po aktualizacji do wersji beta 7, czy mógłbyś podać swoje pliki build.gradle –

+0

@SenzoMalinga Po prostu zastąp swoją zależność kotlin tą, którą określiłem w mojej odpowiedzi. Upewnij się, czyszczenie i odbudować. –

+2

Cześć dziękuję, skończyło się na uruchomieniu "./gradlew app: dependencies", aby pokazać mi, z której biblioteki korzystam, po czym wykluczyłem każdą przejściową zależność, która była starsza i powielona, ​​a ja nie potrzebowałem –

0

udało mi się go naprawić po prostu w tym usług baza Play i nie pełne z nich:

- compile 'com.google.android.gms:play-services:11.6.0' 
+ compile 'com.google.android.gms:play-services-base:11.6.0' 

i usuwa zależności appindexing w moim Aktywny:

-import com.google.android.gms.appindexing.AppIndex; 
-import com.google.android.gms.common.api.GoogleApiClient; 

(choć może to mieć i tak pozostało z mojej aktualizacji do API 27).

2

add to

defaultConfig { 
    multiDexEnabled true 
} 

tak:

android { 
compileSdkVersion 25 
buildToolsVersion "26.0.2" 
defaultConfig { 
    applicationId "com.connectus.connectus" 
    minSdkVersion 16 
    targetSdkVersion 25 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
} 

defaultConfig { 
    multiDexEnabled true 
} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
packagingOptions { 
    exclude 'META-INF/INDEX.LIST' 
} 

}