Multidex issue in Android

柔情痞子 提交于 2019-12-11 03:08:53

问题


I dont Know how to solve Multidex issue in Android. My app has lots of SDKs integration, so App is crossing 65k Over Method limit. I went through lots of tutorials and blogs. I got so many solutions. One of them is below mentioned as part of my gradle. Please someone provide a good and working solution.

android {
minSdkVersion 16
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "your.package.name"
    ..........    }

buildTypes {
    release {
     .............................
    }
}
// Inside android part of build.gradle
dexOptions {
    preDexLibraries = false
}

} 
 .............
 ............

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
 ..................

 // Inside dependencies part of build.gradle
compile 'com.android.support:multidex:1.0.1'
..............
 }


 // Outside android part of build.gradle
afterEvaluate {
tasks.matching {
    it.name.startsWith('dex')
}.each { dx ->
    if (dx.additionalParameters == null) {
        dx.additionalParameters = []
    }
    dx.additionalParameters += '--multi-dex'
   }

 ........
 .......
}

回答1:


This what we have been using in our project. It seem to work just fine. If you have a machine with low memory, you should lover the 2g parameter as it means that multidex can use up to 2GB of memory. This wasn't an issue for us.

 defaultConfig{
       // All other stuff you have, just add this line
       multiDexEnabled true
    }   

dexOptions {
        incremental true
        javaMaxHeapSize "2g"
    }

dependencies {
   'com.android.support:multidex:1.0.1'
}

In your project you should create an Application class and it should extend the MultiDexApplication

    import android.support.multidex.MultiDexApplication;
    public class YourApllication extends MultiDexApplication {

        @Override
        public void onCreate() {
          super.onCreate();
      }
   }


来源:https://stackoverflow.com/questions/29833391/multidex-issue-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!