現象
それなりに大きなモジュールだったり、モジュールが参照するモジュールがたくさんあったりすると、ProGuard が頑張らないといけないことが多くなるので、その分 Java のヒープを食います。
そうすると、いつかヒープが足らなくなり、以下のようにエラーを吐いてビルドがコケるようになります。
:MyApplication:proguardProductionRelease
Note: there were 979 duplicate class definitions.
:MyApplication:proguardProductionRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':NohanaPhotoBook:proguardProductionRelease'.
> Java heap space
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
回避策
ヒープを大きくしましょう。
export GRADLE_OPTS=-Xmx2048m