How to enable multidexing with the new Android Multidex support library

后端 未结 14 2407
逝去的感伤
逝去的感伤 2020-11-21 12:57

I want to use the new Multidex support library to break the method limit for one of my apps.

With Android Lollipop Google introduced a multidex support library that

相关标签:
14条回答
  • 2020-11-21 13:59

    With androidx, the classic support libraries no longer work.

    Simple solution is to use following code

    In your build.gradle file

    android{
      ...
      ...
      defaultConfig {
         ...
         ...
         multiDexEnabled true
      }
      ...
    }
    
    dependencies {
      ...
      ...
      implementation 'androidx.multidex:multidex:2.0.1'
    }
    

    And in your manifest just add name attribute to the application tag

    <manifest ...>
        <application
            android:name="androidx.multidex.MultiDexApplication"
         ...
         ...>
             ...
             ...
        </application>
    </manifest>
    

    If your application is targeting API 21 or above multidex is enables by default.

    Now if you want to get rid of many of the issues you face trying to support multidex - first try using code shrinking by setting minifyEnabled true.

    0 讨论(0)
  • 2020-11-21 14:02

    just adding this snipped in the build.gradle also works fine

    android {
       compileSdkVersion 22
       buildToolsVersion "23.0.0"
    
         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22
    
             **// Enabling multidex support.
             **multiDexEnabled true****
         }
    }
    
    0 讨论(0)
提交回复
热议问题