title: Android MultiDex - Questions on Inner Workings
body: <p>I recently discovered the new MultiDex functionality from Android for working with apps having more than 65,000 references.  See: <a href="https://developer.android.com/tools/building/multidex.html" rel="noreferrer">https://developer.android.com/tools/building/multidex.html</a></p>
  
  <p>Can someone help me understand the following questions:</p>
  
  <p>1) How does the Gradle build plugin determine what to put in the primary dex file (classes.dex) vs the secondary dex files?  Based on the doc there are certain things required to be in primary dex but it doesn't give any examples.  Are all activities required to be in the primary dex file?</p>
  
  <p>Quoted Text:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>2) When building only for Android API Level 21 (Android L) and above, there is different behavior in the Gradle Build Plugin.  It says it is much faster because it "Builds each module of the application (including dependencies) as separate dex files. This is commonly referred to as pre-dexing."  What is the definition of a module in Android?  Is this the Java Library, Android Library, and Android application modules mentioned here: <a href="http://developer.android.com/sdk/installing/studio-build.html#projectModules" rel="noreferrer">http://developer.android.com/sdk/installing/studio-build.html#projectModules</a>?  Do Remote or Local Binary Dependencies (ex:Jars) count as separate modules and thus get put into a different dex file or do they get included in the module depending on them?</p>