使用 DexGuard 构建 Release APK 时获取 java.lang.OutOfMemoryError

Getting java.lang.OutOfMemoryError while building Release APK with DexGuard

在使用最新的 dexguard 版本 9.1.13 构建发布 APK 时,我在应用程序启动时得到 java.lang.OutOfMemoryError,即 Splash Activity。

java.lang.OutOfMemoryError: Failed to allocate a 574109856 byte allocation with 938429 free bytes and 253MB until OOM, target footprint 3753717, growth limit 268435456 at com.paymax.mfs.subscriber._AppController.onCreate(Unknown Source:131) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1242) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7218) at android.app.ActivityThread.access00(ActivityThread.java:269) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:257) at android.app.ActivityThread.main(ActivityThread.java:8218) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)

以下是 build.gradle(应用级别)

中的 dexguard 设置
dexguard {
overwriteUnprotected = true
path = 'path\DexGuard-9.1.13'
license = 'path\DexGuard-9.1.13\lib\dexguard-license.txt'
configurations {
    release {
        defaultConfiguration 'dexguard-release-aggressive.pro'
        configuration 'dexguard-project.txt'
        configuration 'proguard-rules.pro'
        defaultConfiguration 'dexguard-rasp.pro'

    }
}

}

经过一番努力,我得出结论,这个错误是由于 Dex-guard 中的 Certificate Temper 检测功能引起的。我们必须在 Dex-guard 规则中添加 SHA-256 哈希。