1

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",

NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • 3
    Did you read the section of the documentation for "Multidex support for Android 5.0 and higher"? – OneCricketeer Mar 22 '16 at 13:12
  • yes, did you read my question? – NullPointerException Mar 22 '16 at 14:12
  • 1
    Yes I did. You copied the full section of the documentation from "Limitations of the multidex support library". If you read the section I referred to, then you would see "Android 5.0 and higher uses a runtime called ART which natively supports loading multiple dex files from application APK files". Thus, the short answer to your question is you don't need multidex. – OneCricketeer Mar 22 '16 at 14:47
  • before asking this question, I tryed doing it without multidexEnabled true in defaultConfig and it gives me compile error, "method limit exceeded", using targetsdkversion 21 and minsdkversion 21. Test it please. It is easy to surpass 65K limit, just adding full google play services, full appcompat v8, support v4 etc... and maybe some third party sdks and you surpass the limit. – NullPointerException Mar 22 '16 at 14:53
  • 1
    Did you enable the ART runtime from the developer options? – OneCricketeer Mar 22 '16 at 14:58
  • Are you saying that users must enable ART manually in developer options to run my app? – NullPointerException Mar 22 '16 at 15:00
  • According to that duplicate, the 65K problem exists for both. – OneCricketeer Mar 22 '16 at 15:01
  • so, i'm in the exact same starting point of my question, 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? will be necesary for the users to enable art manually? will not? – NullPointerException Mar 22 '16 at 15:03
  • it seems that in 5.0 dalvik is not accessible, my device is using ART, so i dont understand google documentation... it says that using art this problem was solved in the official documentation, but it is not working – NullPointerException Mar 22 '16 at 15:06
  • I can test myself. You said just add the play-services and some others? – OneCricketeer Mar 22 '16 at 15:12
  • full gps, full, support v4, full support appcompat etc... should be easy to reach the limit adding full versions of google libraries – NullPointerException Mar 22 '16 at 15:30
  • i think that it is mandatory to put multidexEnabled true in defaultConfig when compiling with minsdk to 21, it is not well explained in the documentation... – NullPointerException Mar 22 '16 at 15:31
  • If you make an Android Studio project with a min of 21, will it put mutlidex in the gradle? I just use IntelliJ, so I don't know what the templates generate in Android Studio. – OneCricketeer Mar 22 '16 at 15:32
  • no, i put it manually – NullPointerException Mar 22 '16 at 15:46

0 Answers0