-2

When I'm building my project by "Run (applicaton)" build-in function - everything's fine, I can test my app through phone, but I want to create standalone application by gradle.

I'm using gradle :client:clean :client:assemble task, and that's my output:

Dex: Error converting bytecode to dex:sesWithDexForDebug
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
    UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

By this link I've searched for some dependencies between my modules. I checked, that appcompat-v7 and design library have support-v4 library build-in, so I removed it from design library.

My build.gradle file:

dependencies {
    //compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    //Support Design
    compile ('com.android.support:appcompat-v7:23.4.0')
    compile ('com.android.support:design:23.4.0') {
        exclude module: 'support-v4'
    }
    //Butter Knife
    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    //Retrofit
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
    //JSON Utils
    compile 'com.google.code.gson:gson:2.5'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    //Dagger 2
    compile 'com.google.dagger:dagger:2.9'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
    provided 'javax.annotation:jsr250-api:1.0'
    //Android Plot
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
    //Apache Commons
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
    //RxJava
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    //Tests
    testCompile 'junit:junit:4.12'
}

How can I fix it?

Regards

EDIT

I added multiDexEnabled true, and it gaves me another error:

Error:Execution failed for task ':client:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/hardware/display/DisplayManagerCompat$JellybeanMr1Impl.class
Community
  • 1
  • 1
KurdTt-
  • 449
  • 1
  • 5
  • 21

2 Answers2

0

When your app has over 64k methods, you must enable Multidex. Usually this happens when a large number of libraries are used.

To get around this, enable Multidex in your build.gradle

android {
    defaultConfig {
        ...
        minSdkVersion 21
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

Read more about Multidex here.

Charlie
  • 2,876
  • 19
  • 26
0

Just change this attribute

multiDexEnabled false to multiDexEnabled true

Andie
  • 96
  • 3
  • 21