Android Studio Google JAR file causing GC overhead limit exceeded error
To relieve the GC overhead limit exceeded
error caused by Google JAR file in Android Studio, hike up the heap size for Gradle within the gradle.properties
. Simply insert:
org.gradle.jvmargs=-Xmx2048m
By doing so, you assign 2GB to Gradle, potentially dissipating memory limitations. Test the waters and confirm that your system can yield the additional RAM. If the error persists, it's time to streamline your building process by pinpointing and optimizing memory-intensive operations.
Remedial actions
Beefing up build.gradle
dex options
Try feeding it more memory:
This change supersizes the heap limit for dexing, a coder's version of an all-you-can-eat buffet.
Updating Android Studio
Make sure you're dining with the latest Android Studio 1.1.0 or even newer versions. The older ones are yesterday's news and don't handle the memory management as smoothly.
Optimizing your build
- Dish up the incremental builds with
android.useIncrementalCompilation=true
- If your project doesn't feature multiple modules, set
android.preDexLibraries=false
//it's not a multi-layered lasagna - Go to Android Studio Preferences and disable Instant Run to potentially boost performance.
Tweaking dependencies and code
- Pare down dependencies to lighten the memory load.
- Make sure your code is watertight, with no memory leaks or inefficient practices seeping through.
Harnessing Gradle capabilities
Adjust your gradle.properties
like this:
These settings unlock a variety of Gradle performance goodies, such as parallel execution and on-demand configuration.
Keeping an eye on memory usage
Stay alert for large pidXXX.hprof files, which flag memory dumps and possible leaks. //Think of them as footprints left by a naughty memory thief
Expanding Android Studio and Gradle Daemon memory
In Android Studio's memory settings:
- Pump up IDE memory to at least 1GB by adjusting
Xmx
value - Feed the gradle daemon more memory via
org.gradle.jvmargs
Fostering community support
- Don't shy away from shedding light on your project on platforms such as Github.
- Connect with Android development communities for shared problem-solving.
Was this article helpful?