Design Support Library v22.2 "UNDEFINED-TOP-LEVEL EXCEPTION"
I decided to use some cool stuff that Google just released in their support design library. Everythyng is great when I import the library and when I sync the project with Gradle files. But this leads to an error when compiling the project. I don't know if I have too many lirbars, because everything went fine until I replaced the AppCompat library with the design library.
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to execute command: / Users / stanete / Library / Android / sdk / build -tools / 22.0.1 / dx --dex --output / Users / stanete / Workspace / CervezaYa / cervezaya / app / build / intermediates / dex / debug --input- list = / Users / stanete / Workspace / CervezaYa / cervezaya / app / assemblies / intermediate / tmp / dex / debug / inputList.txt Error code: 2 Conclusion: UNDEFINED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: Method ID not in [0, 0xffff]: 65536 at com.android.dx.merge.DexMerger $ 6.updateIndex (DexMerger.java:502) at com. android.dx.merge.DexMerger $ IdMerger.mergeSorted (DexMerger.java:277) at com.android.dx.merge.DexMerger.mergeMethodIds (DexMerger.java:491) at com.android.dx.merge.DexMerger.mergeDexes ( DexMerger.java:168) at com.android.dx.merge.DexMerger.merge (DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers (Main.java:454) at com.android.dx.command .dexer.Main.runMonoDex (Main.java:303) at com.android.dx.command.dexer.Main.run (Main.java:246) at com.android.dx.command.dexer.Main.main (Main .java: 215) at com.android.dx.command.Main.main (Main.java:106)
Here is my build.gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.19.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.coolapp.coolapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
// Third party custom UI
compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
compile 'com.makeramen:roundedimageview:2.0.1'
compile 'com.afollestad:material-dialogs:0.7.4.1'
compile 'com.appyvet:materialrangebar:1.0'
// Views Injection
compile 'com.jakewharton:butterknife:6.1.0'
// Image Processing
compile 'com.squareup.picasso:picasso:2.5.0'
// Event bus
compile 'com.squareup:otto:1.3.6'
// Best mobile DataBase ever
compile 'io.realm:realm-android:0.80.3'
// Dependencies Injection with Dagger
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.dagger:dagger:1.2.2'
// Network
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
// Fonts
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
// Smart location
compile('io.nlopez.smartlocation:library:3.0.10') {
transitive = false
}
// Facebook SDK
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
compile files('libs/simple.facebook-2.2.jar')
// Crashlytics
compile('com.crashlytics.sdk.android:crashlytics:2.2.4@aar') {
transitive = true;
}
}
source to share
This means that your project has reached its limit. Read: https://developer.android.com/tools/building/multidex.html
You need to enable multidex, which you can do:
defaultConfig {
...
multiDexEnabled true
}
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
}
extend Application class with MultiDexApplication and edit your AndroidManifest.xml as described in the link itself.
source to share
I had the same problem because as google says:
If the number of method references in your application exceeds the 65K limit, your application may not compile.
so you exceeded the 65k limit
These are several solutions:
- Enable Proguard
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
- Use multidex, just add:
debug { multiDexEnabled true }
- Just remove the dependencies that you don't really need.
source to share