Android Gradle构建中运行Proguard时堆空间不足

10

当我尝试在Gradle构建中从本地计算机上运行Proguard时,会出现“Java堆空间”错误。具体来说:

:<app_name>:proguardRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':<app_name>:proguardRelease'.
> Java heap space

我尝试设置GRADLE_OPTS=-Xmx2048m,但仍然遇到堆空间错误。

有什么建议吗?

这是我的日志输出末尾:

:Tinder:proguardRelease
ProGuard, version 4.9
Reading input...
Reading program directory [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/classes/release]
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/library.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/androidannotations-api-2.7.1.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/picasso-1.1.1.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/gcm.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/ViewPagerIndicator.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/nineoldandroids.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/crittercism_v3_0_11_sdkonly.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/google-play-services.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/facebook.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/PullToRefresh.aar/classes.jar] (filtered)
Reading program jar [/Applications/android-studio.app/sdk/extras/android/m2repository/com/android/support/support-v4/13.0.0/support-v4-13.0.0.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/apphance-library.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/simple-crop-image-lib.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/windowed-seek-bar.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/com.kontagent.android.sdk.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/ActionBarSherlock.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/google-play-services_lib.aar/classes.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/libs/gson-2.2.4.jar] (filtered)
Reading program jar [/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/build/exploded-bundles/volley.aar/classes.jar] (filtered)
Reading library jar [/Applications/android-studio.app/sdk/platforms/android-17/android.jar]
:Tinder:proguardRelease FAILED
2个回答

14

你是否也导出了环境变量(在Linux和BSD上)?

export GRADLE_OPTS=-Xmx2048m

谢谢!运行得很好。我的构建在任务“shrinkReleaseMultiDexComponents”中出现了错误。 - Ferran Maylinch

3

如果在AndroidStudio中遇到这个问题,没有Gradle,解决方案是为proguard添加一些内存:

Android Studio >> Preferences >> Compilers >> 
Android Compiler >> Proguard Options = -Xmx2048m

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接