问题
I ran into a nasty problem. In my project I have a library (.aar) file which is including an appcompat-v7 compatibility library. Now in my project I also have another appcompat-v7 under the dependency section of gradle.build (app) file..
The problem is when I run the Application it throws an exception saying
UNEXPECTED TOP-LEVEL EXCEPTION:com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;
Here is my application gradle.build (app) file relevant part (I think so)
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile(name: 'conversityChat-debug', ext: 'aar') {
exclude group: 'com.android.support', module: 'support-v7'
}
}
And here is my library gradle.build(app) file relevant part (I think so)
dependencies {
compile project(':androidwebsocketsmaster')
compile 'com.android.support:appcompat-v7:22.2.1'
compile files('libs/acra-4.5.0.jar')
compile files('libs/universal-image-loader-1.9.4.jar')
}
I'm using android studio.. I know this question has been asked before, and I've tried out all possible solutions suggested over there. Sadly, None of them helped... Please help me out
回答1:
Add below code to your gradle :
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
Add below dependency and add HttpCore and HttpClient also.
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
For more information check below link :
https://developer.android.com/tools/building/multidex.html
Thanks..!!
回答2:
Remove
compile 'com.android.support:appcompat-v7:22.2.1'
from your outer level build.gradle file (the top one) you only need it in your project level build.gradle file.
来源:https://stackoverflow.com/questions/33123181/appcompat-v7-conflict-in-android