If I run gradle assembleDebug
from the command line, I am suddenly getting this error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.util.DexEx
Deleting all files from Gradle cache fixed my problem.
on Linux:
rm -rf ~/.gradle/caches/*
Also to note you can see your android dependencies, by going to your Android Studio Gradle view, and selecting the target "androidDependencies".
One more tip: I was having this issue, until I removed the v4 support lib from the libs folder in both the project and my related module/library project(s).
I started getting this error when upgrading to ButterKnife 8.5.1. None of the other answers here worked for me.
I used gradle -q :app:dependencies
to see the tree, and then looked through jar files until I found the conflict. The conflict was that butterknife's dependency on com.android.support:support-compat:25.1.0
contains a version of the accessibility class, and com.android.support:support-v4:23.1.1
also contains the class.
I solved it by changing my dependency from this:
compile 'com.jakewharton:butterknife:8.5.1'
to this:
compile('com.jakewharton:butterknife:8.5.1') {
exclude module: 'support-compat'
}
It doesn't seem to affect ButterKnife's operation so far.
Edit: There is a better solution, which was to upgrade my android support libraries to match ButterKnife's:
compile('com.android.support:appcompat-v7:25.2.0')
compile('com.android.support:design:25.2.0')
compile 'com.jakewharton:butterknife:8.5.1'
In case anyone finds out that the answer from CommonsWare could not be applied to android library project, here is the snippet to fix
compile (project(':yourAndroidLibrary')){ exclude module: 'support-v13' }
You will find problems
Unsupported Gradle DSL method found: 'exclude()'
if you use compile project(':yourAndroidLibrary'){ exclude module: 'support-v13' }
The differences are the bracelet "(" and ")" before "project".
I'm using com.google.android.gms:play-services-analytics:8.3.0
and
android-support-v13.jar
and could not get exclude module: 'support-v4'
to work.
What worked for me was using the android-support-v13
artefact rather than the android-support-v13.jar
file.
I.e. instead of
dependencies {
compile ('com.google.android.gms:play-services-analytics:8.3.0')
compile files('libs/android-support-v13.jar')
}
I used
dependencies {
compile ('com.google.android.gms:play-services-analytics:8.3.0')
compile ('com.google.android:android-support-v13')
}
A similar dex issue resolved method
gradle.build was containing:
compile files('libs/httpclient-4.2.1.jar')
compile 'org.apache.httpcomponents:httpclient:4.5'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
The issue was resolved when i removed
compile files('libs/httpclient-4.2.1.jar')
My gradle now looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.mmm.ll"
minSdkVersion 16
targetSdkVersion 24
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:6.1.+'
compile files('libs/PayPalAndroidSDK.jar')
compile files('libs/ksoap2-android-assembly-3.0.0-RC.4-jar-with-dependencies.jar')
compile files('libs/picasso-2.1.1.jar')
compile files('libs/gcm.jar')
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}
There was a redundancy in the JAR file and the compiled gradle project
So keenly look for dependency and jar files having same classes.
And remove redundancy.
This worked for me.