Android methods are more than 64 k, OOM compilation, and slow compilation solutions ., Androidoom
Now, the project's leancloud instant messaging is changed to instant messaging. When easeui is introduced, the number of methods exceeds the upper limit.
Search for the problem and the solution is simple.
Here is a simple record, which records another problem caused by this solution in sequence.
I. solution: the number of solutions exceeds 64 KB
Problem description:
Error:The number of method references in a .dex file cannot exceed 64K.Error:Execution failed for task ':app:transformClassesWithDexForRelease'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
Solution:
1. build. gradle in the app directory
dependencies { ..... compile 'com.android.support:multidex:1.0.1' }
2. Add in defaconfig config
defaultConfig { applicationId "com.maiji.magkaredoctor" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" multiDexEnabled true }
3. Add a method to the class that inherits the Application written by the user.
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this) ; }
Ii. Compilation of OOM
The easeui of huanxin is introduced, resulting in a sudden slowdown in Compilation speed and frequent OOM compilation.
After querying many methods, the test did not solve the problem. Final Solution
Add android {} to the build. gradle file in the app directory
dexOptions { incremental true javaMaxHeapSize "4g" }
Another method to increase Compilation speed:
Add the following content to the android {} of the build. gradle file in the app directory:
tasks.whenTaskAdded { task -> if (task.name.contains("lint") || task.name == "clean" || task.name.contains("Aidl") || task.name.contains("mockableAndroidJar") || task.name.contains("UnitTest") || task.name.contains("AndroidTest") || task.name.contains("Ndk") || task.name.contains("Jni") ) { task.enabled = false } }
Note: here we cancel these tasks. For example, if Ndk is used in your project, you should not write task. name. contains ("Ndk.