There is one strange error I have encountered while trying to build an Android application with IntelliJ IDEA. Gradle crashed with a mysterious message: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define
. There are several solutions available for Eclipse and several solutions available for IDEA (this one is my favorite), but none of them worked in my case.
This error started to come up after updating IDEA Gradle plugin from 0.6.+ to 0.7.+ (and corresponding Gradle distribution from 1.8 to 1.9). To verify which plugin version you are using, look at the following line in the build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
Next thing I found during my investigation to solve this error was the folder named “.gradle” in the project dir. Its content actually clarified much. In this folder Gradle kept task artifacts for building process, both 1.8 and 1.9. Somehow it was causing build conflict. Deleting this folder did the trick, Gradle has recreated it with newer artifacts only and that solved the entire problem.
UPD: Today IDEA suggested to migrate my projects to plugin version 0.9.+ and Gradle version 1.11 due to some breaking changes. No errors this time.