Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes on launch when building a variant release #24854

Closed
mkrotel14 opened this issue May 14, 2019 · 11 comments
Closed

App crashes on launch when building a variant release #24854

mkrotel14 opened this issue May 14, 2019 · 11 comments
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@mkrotel14
Copy link

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,
  },
});
@mkrotel14 mkrotel14 added the Bug label May 14, 2019
@react-native-bot react-native-bot added the Platform: Linux Building on Linux. label May 14, 2019
@kylethielk
Copy link

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.

@JijoBose
Copy link

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

@kelset
Copy link
Contributor

kelset commented May 15, 2019

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.

@jedsada-jed
Copy link

I found problem same you but my platform is windows.

@kelset kelset added Platform: Android Android applications. and removed Platform: Linux Building on Linux. labels May 20, 2019
@kelset
Copy link
Contributor

kelset commented May 20, 2019

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: 30348f7

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: react-native-community/releases#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)

@kelset kelset closed this as completed May 20, 2019
@albat
Copy link

albat commented May 20, 2019

Thanks for your reply :)

@mkrotel14
Copy link
Author

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

@dudeinthemirror
Copy link

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
. . .

@rkalapuc
Copy link

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)
                }
            }
        }
    }
}

@aminyousefiadl
Copy link

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

@ghost
Copy link

ghost commented Apr 18, 2020

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

@facebook facebook locked as resolved and limited conversation to collaborators May 20, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

10 participants