React Native: Java heap space



我目前正在用react native构建我的android APK,遵循doc.

我得到这个错误:

./gradlew bundleRelease
WARNING:: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
This repository is deprecated and it will be shut down in the future.
See http://developer.android.com/r/tools/jcenter-end-of-service for more information.
Currently detected usages in: project ':react-native-async-storage_async-storage', project ':react-native-camera', project ':react-native-pager-view', ...
> Task :app:signReleaseBundle FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:signReleaseBundle'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.FinalizeBundleTask$BundleToolRunnable
> Java heap space
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 15s
213 actionable tasks: 15 executed, 198 up-to-date

当我运行./gradlew signingReport时一切正常:

WARNING:: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
This repository is deprecated and it will be shut down in the future.
See http://developer.android.com/r/tools/jcenter-end-of-service for more information.
Currently detected usages in: project ':react-native-async-storage_async-storage', project ':react-native-camera', project ':react-native-pager-view', ...
> Task :app:signingReport
Variant: debug
Config: debug
Store: /home/alexandre/Documents/project/iWaiterApp/android/app/debug.keystore
Alias: AndroidDebugKey
MD5: 20:F4:61:48:B7:2D:8E:5E:5C:A2:3D:37:A4:F4:14:90
SHA1: 5E:8F:16:06:2E:A3:CD:2C:4A:0D:54:78:76:BA:A6:F3:8C:AB:F6:25
SHA-256: FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C
Valid until: Tuesday, April 30, 2052
----------
Variant: release
Config: release
Store: /home/alexandre/Documents/project/iWaiterApp/android/app/my-upload-key.keystore
Alias: my-key-alias
MD5: 86:65:36:56:D2:FE:31:9A:5D:B1:2B:67:B2:0E:57:C4
SHA1: 25:90:1A:0B:0C:4E:95:CE:CE:E2:40:5F:B9:0E:D6:46:0D:41:F9:45
SHA-256: BC:82:0F:E2:FC:24:52:DB:14:95:CD:D7:06:9B:D6:CB:50:F1:44:85:FC:EC:4C:65:CD:CB:10:8B:E8:00:04:9C
Valid until: Wednesday, February 3, 2049
----------
// ...
----------
Variant: releaseUnitTest
Config: debug
Store: /home/alexandre/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 20:F4:61:48:B7:2D:8E:5E:5C:A2:3D:37:A4:F4:14:90
SHA1: 5E:8F:16:06:2E:A3:CD:2C:4A:0D:54:78:76:BA:A6:F3:8C:AB:F6:25
SHA-256: FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C
Valid until: Tuesday, April 30, 2052
----------
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 5s
11 actionable tasks: 11 executed
这是我的android/app/build.gradle
// ...
android {
// ...
signingConfigs {
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'AndroidDebugKey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// ...
}
dependencies {
// ...
}
// ...

这是我的android/gradle.properties

android.useAndroidX=true
android.enableJetifier=true
FLIPPER_VERSION=0.93.0
MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=computer
MYAPP_UPLOAD_KEY_PASSWORD=computer

我可以找到一个方法来解决这个问题:

  • React Native Task:app:validateSigningDebug FAILED

我也使用debug.keystore的官方模板:https://raw.githubusercontent.com/facebook/react-native/master/template/android/app/debug.keystore

如何解决这个问题?

即使在签名步骤中出现错误,似乎也与此无关,而只是java内存不足。

尝试将下面的行添加到gradle中。

org.gradle.jvmargs=-Xmx2g -XX:MaxHeapSize=4g

最新更新