How to enable multidexing with the new Android Multidex support library

后端 未结 14 2731
逝去的感伤
逝去的感伤 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

    
        
             ...
             ...
        
    
    

    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.

提交回复
热议问题