Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactNative 0.59.x build fails on CircleCI with exit value 137

When building the app on CircleCI for v0.59.x it gives me the following error (It used to work fine till v0.57.8):

[12:45:19]: ▸ Note: Some input files use or override a deprecated API.
[12:45:19]: ▸ Note: Recompile with -Xlint:deprecation for details.
[12:45:19]: ▸ > Task :react-native-svg:processReleaseJavaRes NO-SOURCE
[12:45:19]: ▸ > Task :react-native-svg:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease
[12:45:19]: ▸ > Task :app:javaPreCompileQa
[12:45:44]: ▸ > Task :app:bundleQaJsAndAssets
[12:45:44]: ▸ warning: the transform cache was reset.
[12:46:00]: ▸ Loading dependency graph, done.
[12:46:19]: ▸ > Task :app:bundleQaJsAndAssets FAILED
[12:46:19]: ▸ FAILURE: Build failed with an exception.
[12:46:19]: ▸ * What went wrong:
[12:46:19]: ▸ Execution failed for task ':app:bundleQaJsAndAssets'.
[12:46:19]: ▸ > Process 'command 'node'' finished with non-zero exit value 137

I figure this has something to do with memory or Gradle/Java options because the build works fine on my local machine (./gradlew assembleRelease)

Useful snippets from circle config:

jobs:
  make-android:
    ...
    docker:
      - image: circleci/android:api-28-node8-alpha
    environment:
      TERM: dumb
      # JAVA_OPTS...
      # GRADLE_OPTS...
    steps:
      - checkout:
          path: *root_dir
      - attach_workspace:
          at: *root_dir
      - run:
          name: Build the app
          no_output_timeout: 30m
          command: bundle exec fastlane make

And fastlane make is

gradle(task: "clean")
gradle(task: "assembleRelease")

I tried multiple JAVA_OPTS and GRADE_OPTS, including removing them (it used to work fine with no _OPTS with v0.57.8)

JAVA_OPTS: "-Xms512m -Xmx4096m"
GRADLE_OPTS: -Xmx4096m -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xms512m -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"
JAVA_OPTS: "-Xms512m -Xmx2048m"
GRADLE_OPTS: -Xmx2048m -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"

I also have this in android/app/build.gradle

dexOptions {
    javaMaxHeapSize "2g"
    preDexLibraries false
}
like image 458
Sourabh Avatar asked May 06 '19 10:05

Sourabh


2 Answers

One of the reasons could be the number of workers the Metro bundler is using.

Setting maxWorkers: <# workers> in metro.config.js fixed it for me:

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
  maxWorkers: 2,
};

Other things I changed were set JAVA_OPTS and GRADLE_OPTS in .circle/config.yml

JAVA_OPTS: '-Xms512m -Xmx2g'
GRADLE_OPTS: '-Xmx3g -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx2g -XX:+HeapDumpOnOutOfMemoryError"'
like image 77
Sourabh Avatar answered Nov 20 '22 07:11

Sourabh


For those who are finding this issue on new React native versions.

Most of the time it is related to caching, from the old builds. I'd recommend doing a full clean cache of Gradle and also Xcode:

Gradle:

// Stop daemon running:
cd android && ./gradlew --stop
// Clean cache using:
rm -rf ~/.gradle/caches/

xCode:

// remove old Pods folder
cd ios && rm -rf Pods
// install a clean version of it
pod install --clean-install

That's a common memory android issue, it happened to me React Native version 0.66.x as well.

For me what worked was limiting the Java heap size. Like suggested by @Sourabh.

The first one I change was _JAVA_OPTIONS, which I set to -Xmx3g. This variable tells Java the heap size cannot grow larger than 3GB which is 75% of the default medium resource class. If any other job is working on the CI, it's recommendable to use 2GB instead.

The second change was to change the GRADLE_OPTS as well, pointing to the same 3GB heap size. Also, I made the Kotlin run within the same memory allocation with the option Dkotlin.compiler.execution.strategy=in-process

Both my changes:

_JAVA_OPTIONS: '-Xmx3g -Xmx2048m -XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport'
GRADLE_OPTS: '-Xmx3g -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.compiler.execution.strategy=in-process'
  • Others envars to potentially check it out.
  • Reference: Circle CI Docs.
like image 1
Sayuri Mizuguchi Avatar answered Nov 20 '22 06:11

Sayuri Mizuguchi