We've been having problems recently with Multidexing, specifically when building for the Dalvik VM using the gradle multidex plugin ('com.android.support:multidex:1.0.0').
It appears as if gradle has difficulty resolving the correct classes which should be included in the main dex file. As a result, we end up with a build process which completes successfully, but sometimes produces a main dex file which does not include a class or classes which are required to correctly instantiate the main application (which itself extends MultiDexApplication).
Our current solution to brute force a consistent build was to monitor the intermediate files generated by multidex. When we had a good build (i.e. one which correctly instantiated the main App and therefore the MultiDexApplication), then copying the list of classes which were included in the main dex file into a file which we then force multidex to use (using --main-dex-list parameter). This temporarily enabled us to 'force' the required classes into the main dex file, but is obviously not very maintainable and cannot be updated easily when new classes/dependencies are added.
We are using Dagger 2 for dependency injection, and we have a suspicion that this is somehow preventing the multidex plugin from correctly identifying the main App's dependencies - could this be the possible cause? We've also come across various references to using a minimal 'App Wrapper' (which itslef extends MultiDexApplication) as the 'entry point' for multidexing, but could not find sufficient documentation on the process to proceed.
Would be great if you could provide some insight on this - is this a problem you have experienced before? Is there a known workaround? Any details you could provide on how we could implement teh 'App Wrapper' pattern would also be very much appreciated
The new support v4 library has multidex included, have you tried using that?
add the following to your gradle dependencies:
compile "com.android.support:support-v4:$21.0.+"
and add this flag to your android > defaultConfig in gradle
android{
defaultConfig{
....
multiDexEnabled true
}
}