Android methods are more than 64 k, OOM compilation, and slow compilation solutions ., Androidoom

Source: Internet
Author: User

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.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.