React-native: Android release build crashes but develop build is fine

Created on 8 Oct 2018  路  9Comments  路  Source: facebook/react-native

Environment

React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
      Memory: 30.29 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 9.0.0 - ~/.nvm/versions/node/v9.0.0/bin/node
      Yarn: yarn install v0.19.1
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 11.74s. - /usr/local/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v9.0.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
      Android SDK:
        Build Tools: 23.0.1, 26.0.3, 27.0.3
        API Levels: 23, 26, 27
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5014246
      Xcode: 10.0/10A255 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.5.0 => 16.5.0
      react-native: 0.57.2 => 0.57.2
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Description

After successfully creating a release Android apk and attempting to run the build by itself using react-native run-android --variant=release, the app will load its first screen successfully. The splash and first screen successfully load with a large image asset as the background. However upon attempting to navigate to the second page (React-navigation and FlatList) the app crashes, but only in the android release apk, never on dev.

Examining the adb logs shows a potential lead on the culprit:

--------- beginning of crash
AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: Process: com.awesomeproject, PID: 5018
AndroidRuntime: java.lang.RuntimeException: Canvas: trying to draw too large(564550364bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)
at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:529)

...etc

Before the crash were a number of

W unknown:WrappingUtils: Don't know how to round that drawable: com.facebook.f.e.l@8aa7709

before the VM shut down.

Reproducible Demo

Not sure if this is possible to share on snack.expo since this regards release builds. There's no crash on dev.

Things I tried

Updating `android/app/build.gradle' to include the following three items in the project.ext.react array:

project.ext.react = [
    entryFile: "index.js",
    bundleInRelease: true,
    jsBundleDirRelease: "$buildDir/intermediates/assets/release",
    resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
]

also tried resourcesDirRelease: "src/release/res"

ran gradle clean and a new gradle assembleRelease (always with success) but the resulting APK keeps failing with that same crash log.

Thanks for reading.

Android Locked

Most helpful comment

To anyone facing the same problem. This stackoverflow issue worked for me. 馃帀馃帀馃帀馃帀

All 9 comments

same issue here, app crashes with "unfortunately, app has stopped" message

As a temporary workaround you can try this suggestion from 'Indivision Dev' on SO.
https://stackoverflow.com/questions/45096794/gradlew-assemblerelease-command-in-react-native-android-is-not-generating-the-ap
Note that try first without deleting the android/app/src/main/res/drawable-* as 'Indivision Dev' suggests.

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/release/

react-native run-android --variant=release

This is most likely the a duplicate of https://github.com/facebook/react-native/issues/21132

@levynir I think this case may be related but different - the splash and first screen successfully loads with an image asset, but the navigation to a second route that includes FlatList is where the crash occurs.

in my experience crashes in release build is usually due to code errors.

no real sure way to resolve this other than stepping thru the code, yeah block by block or line by line until you get to the part where it crashes.

normally narrow it down first by commenting out scenes then narrow down to component level.

usual culprits
polyfills, undefined blah blah, console.log this spams

Try to run react-native run-android --variant=release without running adb reverse tcp:8081 tcp:8081. It worked for me

Thanks to alternative bundler haul (https://github.com/callstack/haul) I was able to get a slightly more informative warning upon bundling that I did not get in my development build - one of the assets I was attempting to use in my bundle (that only appeared on the second screen) was way too big and was causing the release bundle to crash. Very curious that it wasn't causing the development build to crash. The logcat did inform me that Canvas: trying to draw too large but a more specific warning about one of the images I was bundling being too large helped me make this easy fix.

Thanks for all you do with React Native. When you have bandwidth to add warnings about image sizes I know it would help a lot of developers.

I am also facing same issue after upgrading gradle version from 4.10 to 4.6 and classpath 2.3.3 to 3.2.1.
Debug build is working but production release is failing.
Let us know if someone has done migration of RN android project.

To anyone facing the same problem. This stackoverflow issue worked for me. 馃帀馃帀馃帀馃帀

Was this page helpful?
0 / 5 - 0 ratings