I have the following quarrel:
So for a larger project I require to have multiple Apps with a reusable library module inside of them for several purposes. Unfortunately, it seems that I exceeded the dex limit for my project just with the basic amount of classes and libraries that I have inside my library module with the following gradle dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.2.51"
implementation "org.jetbrains.anko:anko:$anko_version"
implementation 'com.android.support:multidex:1.0.3'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
implementation 'androidx.exifinterface:exifinterface:1.0.0-beta01'
implementation "androidx.browser:browser:1.0.0-beta01"
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.github.ornolfr:rating-view:0.1.2@aar'
implementation 'com.github.siyamed:android-shape-imageview:0.9.3@aar'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
implementation("com.github.bumptech.glide:recyclerview-integration:4.6.1") {
// Excludes the support library because it's already included by Glide.
transitive = false
}
implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
implementation 'io.realm:android-adapters:2.1.1'
}
As you can see its quite a lot of libraries (which I do require). Additionally to that, Ive already enabled multiDex to true, added the support multidex library (as you can see in the dependencies), and I also use a custom Application class that extends from MultidexApplication
But unfortunately I still get the
Error: Cannot fit requested classes in a single dex file (# methods: 68405 > 65536)
error during build. The only option that seemed to solve it was setting my minSDK from 19 to 21, but I require to have it at 19 for the project.
Does anybody have an idea what I might also try to fix it?
You are currently using the support multidex library but you've upgraded to use androidx.
Therefore, You need to use the androidx version.
ie:
replace implementation 'com.android.support:multidex:1.0.3'
with implementation 'androidx.multidex:multidex:2.0.0'
Implementing a multidex for below API 21 is a two steps process.
First step:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
Second step: Exted your application class from MultidexApplication.
public class MyApplication extends MultiDexApplication { ... }
Or if you don't have a custom application class then change your AndroidManifest.xml class like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
Happy Coding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With