14

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
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Sourabh
  • 8,243
  • 10
  • 52
  • 98
  • The key log lines are `Task :app:bundleQaJsAndAssets FAILED` and `FAILURE: Build failed with an exception`, but they do not seem to offer much detail. Are there more logs you can get your hands on? I appreciate it works on your development machine, but this may be an ordinary environmental problem, rather than something specific to CircleCI. I recommend using the post-build SSH option so you can run this manually and dig into the `/var/log` folder (or wherever this might write logs). – halfer May 06 '19 at 16:17
  • I wonder if you might be right about memory though, [this error](https://discuss.circleci.com/search?q=137%20order%3Alatest) seems to be mentioned at the same time as memory fixes. – halfer May 06 '19 at 16:20
  • Ooh, I imagine `-Xmx4096m` is going to fail. Assuming you are using a default container size, you will have a RAM limit of 4G for the whole thing, so your JVM should be much less than that. I would suggest going for between 2G and 3G instead. – halfer May 06 '19 at 16:21
  • 1
    The problem was metro, not gradle. `maxWorkers` fixed it – Sourabh May 07 '19 at 17:32
  • Great. Thanks for adding an answer! – halfer May 07 '19 at 18:29

2 Answers2

35

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"'
Sourabh
  • 8,243
  • 10
  • 52
  • 98
  • 2
    This fixed it for me. Max workers specifically. Thank you! – bryan Sep 08 '19 at 23:51
  • Max workers resolved an issue for my team also, thank you! – Josh Buchea Dec 06 '19 at 17:44
  • 1
    For me it took the combination of setting metro maxWorkers to 1 plus these GRADLE_OPTS: `-Xmx3g -Dorg.gradle.workers.max=1 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.jvmargs="-Xmx2g -XX:+HeapDumpOnOutOfMemoryError"` – Dylan Nissley Jun 23 '20 at 21:06
  • Your CI seems to be really low on memory – Sourabh Jun 24 '20 at 10:12
2

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'
Sayuri Mizuguchi
  • 5,250
  • 3
  • 26
  • 53