In the official documentation, I can see that you can use multi-dex in android versions prior to 5.0 using this:
defaultConfig {
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
And it tells that it has some problems and limitations:
Limitations of the multidex support library
The multidex support library has some known limitations that you should be aware of and test for when you incorporate it into your app build configuration:
The installation of .dex files during startup onto a device's data partition is complex and can result in Application Not Responding (ANR) errors if the secondary dex files are large. In this case, you should apply code shrinking techniques with ProGuard to minimize the size of dex files and remove unused portions of code. Applications that use multidex may not start on devices that run versions of the platform earlier than Android 4.0 (API level 14) due to a Dalvik linearAlloc bug (Issue 22586). If you are targeting API levels earlier than 14, make sure to perform testing with these versions of the platform as your application can have issues at startup or when particular groups of classes are loaded. Code shrinking can reduce or possibly eliminate these potential issues. Applications using a multidex configuration that make very large memory allocation requests may crash during run time due to a Dalvik linearAlloc limit (Issue 78035). The allocation limit was increased in Android 4.0 (API level 14), but apps may still run into this limit on Android versions prior to Android 5.0 (API level 21). There are complex requirements regarding what classes are needed in the primary dex file when executing in the Dalvik runtime. The Android build tooling updates handle the Android requirements, but it is possible that other included libraries have additional dependency requirements including the use of introspection or invocation of Java methods from native code. Some libraries may not be able to be used until the multidex build tools are updated to allow you to specify classes that must be included in the primary dex file.
OK, but... what happens if you use minsdkversion and targetsdkversions 21 or higher (android 5.0 and higher) and without adding the support:multidex
library dependency? will these limitations still exist? will be necessary to add multidexEnabled true
in defaultConfig
gradle file?
I tryed doing it without multidexEnabled true in defaultConfig and using targetsdkversion 21 and minsdkversion 21 and it gives me compile error, "method limit exceeded",