React-native: App crashes on launch when building a variant release

Created on 14 May 2019  路  11Comments  路  Source: facebook/react-native

After update my project to the latest version of React-Native, the APK start to crash on launch, so I create a new project with the latest version o RN, without any code and simply run the react-native run-android --variant=release and this new project crash on launch
PS: i configured the keystore and the variant releases in build.graddle

Environment

React Native version:

  info 
  React Native Environment Info:
    System:
      OS: Linux 5.0 Fedora 29 (Workstation Edition) 29 (Workstation Edition)
    Binaries:
      Node: 11.15.0
      Yarn: 1.16.0
      npm: 6.9.0
    SDKs:
      Android SDK:
        API Levels: 27, 28
        Build Tools: 28.0.3
        System Images: android-27 | Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.8 => 0.59.8 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Steps To Reproduce

  1. react-native init foo
  2. Configure the keystore
  3. react-native run-android --variant=release

Expected Behavior

The App should run without any crash or error.
App returns BUILD SUCCESS, but crashes without logging any error on start

Code Example

App.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
Bug Android Locked

Most helpful comment

Hi @GianMantuan I just encountered this too.

By chance I remember being prompted by Android Studio to upgrade my Gradle Version earlier in the day.

I reverted my Gradle version and the issue immediately resolved itself. Here are the gradle changes that Android Studio applied:

Screen Shot 2019-05-14 at 11 13 24 AM

Once I reverted this change and re-built the release variant it worked without issue again.

All 11 comments

Hi @GianMantuan I just encountered this too.

By chance I remember being prompted by Android Studio to upgrade my Gradle Version earlier in the day.

I reverted my Gradle version and the issue immediately resolved itself. Here are the gradle changes that Android Studio applied:

Screen Shot 2019-05-14 at 11 13 24 AM

Once I reverted this change and re-built the release variant it worked without issue again.

Thank you @kylethielk , I tried the same and it worked for me

Hey everyone, thanks for reporting this - it seems to suggest that RN 0.59.x can't be used with Gradle 3.4.0 - I'll ask if it's a known limitation of the current version.

I found problem same you but my platform is windows.

I've investigated and yes, I can confirm that the current latest 0.59.x is NOT compatible with Gradle 3.4.0.

But surely 0.60 will, thanks to this commit: https://github.com/facebook/react-native/commit/30348f789946dc99f5ccd02c85c8decbdb9ac29b

We will try to see if we can cherry pick it for the next 0.59.9, but it's unlikely (you can stay updated here: https://github.com/react-native-community/releases/issues/124).

Please be patient, we are trying to get an 0.60 RC out this week.

(in the meantime I'll close this since it's a known limitation already fixed on master)

Thanks for your reply :)

Thank you @kylethielk, your solution worked for me. It was the Gradle after all...

This might help someone having the same issue: this is the workaround that I found for now:

cd android
./gradlew clean && ./gradlew assemble$FLAVOR --stacktrace
 cp ./app/build/generated/assets/react/$flavor/index.android.bundle ./app/src/main/assets/index.android.bundle
react-native run-android

where $FLAVOR is e.g. Debug and $flavor is debug

I have this in android/build.gradle

dependencies {
        classpath('com.android.tools.build:gradle:3.4.0')
       . . .
    }

and this in gradle-wrapper.properties:

. . .
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
. . .

Try it out guys:

```
gradle.projectsEvaluated {
// grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }

productFlavors.each { productFlavorName ->
    buildTypes.each { buildTypeName ->
        // create variant and target names
        def flavorNameCapitalized = "${productFlavorName.capitalize()}"
        def buildNameCapitalized = "${buildTypeName.capitalize()}"
        def targetName = "${flavorNameCapitalized}${buildNameCapitalized}"
        def targetPath = "${productFlavorName}${buildNameCapitalized}"

        def fixTask = tasks.create(
            name: "react-native-${targetName}FixForGradlePlugin-3.4.x",
            type: Copy
        ) {
            into("${buildDir}/intermediates")

            from("${buildDir}/generated/assets/react/${productFlavorName}/${buildTypeName}") {
                include("index.android.bundle")
                into("merged_assets/${targetPath}/out/")
            }
        }

        fixTask.dependsOn("merge${targetName}Resources")
        fixTask.dependsOn("merge${targetName}Assets")

        [
            "process${flavorNameCapitalized}Armeabi-v7a${buildNameCapitalized}Resources",
            "process${flavorNameCapitalized}X86${buildNameCapitalized}Resources",
            "processUniversal${targetName}Resources",
            "process${targetName}Resources"
        ].each { name ->
            Task dependentTask = tasks.findByPath(name);

            if (dependentTask != null) {
                dependentTask.dependsOn(fixTask)
            }
        }
    }
}

}

Hi @GianMantuan I just encountered this too.

By chance I remember being prompted by Android Studio to upgrade my Gradle Version earlier in the day.

I reverted my Gradle version and the issue immediately resolved itself. Here are the gradle changes that Android Studio applied:

Screen Shot 2019-05-14 at 11 13 24 AM

Once I reverted this change and re-built the release variant it worked without issue again.

how to revert the Gradle ? mine was 6.0.1 from begining

Same issue on android 5.0.1 only it is ok on android 6

Was this page helpful?
0 / 5 - 0 ratings