2

Yesterday, when I've tried to debug my app and run it on my device, the Gradle Console started to show this error right after :mobile:dexDebug:

AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Lcom/parse/ParseFacebookUtils;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lcom/parse/ParseFacebookUtils;"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)","position":{},"original":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)","position":{},"original":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)","position":{},"original":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)","position":{},"original":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:106)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:106)"}


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mobile:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_11\bin\java.exe'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I've did a little research here, and it seems to be related to the dependencies in build.gradle file. All of my SDKs are up to date.

build.gradle (Module: mobile):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.0'

    defaultConfig {
        applicationId "com.intap.tof"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories { mavenCentral() }

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    wearApp project(':wear')
    compile 'com.parse:parse-android:1.+'
    compile fileTree(include: 'achartengine-1.1.0.jar', dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.parse.bolts:bolts-android:1.+'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.jjoe64:graphview:4.0.1'
}
Ido Naveh
  • 2,442
  • 3
  • 26
  • 57

3 Answers3

4

com.android.dex.DexException: Multiple dex files define Lcom/parse/ParseFacebookUtils;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lcom/parse/ParseFacebookUtils;"}

At first Add multidex in your build.gradle section .

  1. Set buildToolsVersion '23.0.1'
  2. set compile 'com.parse.bolts:bolts-android:1.2.1'

  3. set compile 'com.parse:parse-android:1.11.0'

  4. Change your Gradle build configuration to enable multidex

  5. Clean-Rebuild-Sync

Modify your app Gradle build file configuration to include the support library and enable multidex output .

    android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 23
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

For details Please read DexException

https://developer.android.com/intl/es/tools/building/multidex.html

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

You are getting this exception because the application has reached a limit of 64k methods. So, you can enable multidex in your application as correctly suggested in the other answers. But, enabling multidex increases your build time and in many cases it is not preferable.

So, I would suggest you to use different proguard files for debug and release versions(in debug version don't obfuscate variable and class names). Proguard in most cases would help to overcome this exception. If this doesn't work then you would have to use multidex.

Yash Ladia
  • 393
  • 5
  • 15
0

I solved the problem!
I switched back to Parse SDK 1.9.3 and suddenly it works!

Anyway, thank you guys for trying to help me with the question. Very appriciating.

Ido Naveh
  • 2,442
  • 3
  • 26
  • 57