0

I am generating an app for testing but in the end it displays the error java.lang.OutOfMemoryError: GC overhead limit exceeded error.
To fix this issue I followed the solution on this link.
And I have added this line of code in module build.gradle file

dexOptions{
    incremental true
    javaMaxHeapSize "2g"
}

But now it throws another error which says

Gradle sync failed: Could not find method dexOptions() for arguments [build_abwf3h5ru8za0j4597zvncj35$_run_closure2@30ed1096] on project ':app' of type org.gradle.api.Project.
        Consult IDE log for more details (Help | Show Log)


Can you help me to fix this issue ?
Thank you.

1 Answers1

1

If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:

    android {
        defaultConfig {
            ...
            minSdkVersion 21 
            targetSdkVersion 25
            multiDexEnabled true
        }
        ...
}

However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:

Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

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

Depending on whether you override the Application class, perform one of the following: If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows: public class MyApplication extends MultiDexApplication { ... } Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(context);
     Multidex.install(this);
  }
}
Salauddin Gazi
  • 1,497
  • 1
  • 13
  • 18
  • When I added the line android:name="android.support.multidex.MultiDexApplication" in manifest it throws error it the next activity line. I have a AppController file which I want to execute whenever I launch the app. So is it okay if I replace the android:name ? –  Jan 13 '17 at 06:51
  • create a class like "MyApplication" and extends Application class and add "@Override protected void attachBaseContext(Context base) { super.attachBaseContext(context); Multidex.install(this); }" and ... – Salauddin Gazi Jan 13 '17 at 07:02
  • minSdkVersion is 15 –  Jan 13 '17 at 07:32