Skip to content

Release APK crash immediately on launch - React Native ( Version 0.58.4) #23352

Closed
@ank26oct

Description

@ank26oct

🐛 Bug Report

The android version runs perfectly in debug mode using android studio emulator. However, the release version of the apk crashes immediately when launched.

To Reproduce

Steps to reproduce the behavior.

Reproducible Demo

react-native init Demo
cd AwesomeProject

After this Just install following:

npm i --save react-native-crypto
npm i bitcore-lib --save
npm i --save react-native-randombytes
react-native link react-native-randombytes
npm i --save-dev tradle/rn-nodeify
./node_modules/.bin/rn-nodeify --hack --install

rn-nodeify will create a shim.js in the project root directory

import './shim.js' file in aap.js

react-native run-android

It runs perfectly in debug mode.
I have created signed apk it gets created without any error also installed without error but when i open, it crashes

Expected Behavior

The app should run without crashing.
App crashes on launch, logcat throws this error:

02-09 11:18:38.980 13627-13645/com.productionbuild E/ReactNativeJS: undefined is not a function (evaluating 'n.fill(255)')
02-09 11:18:38.995 13627-13645/com.productionbuild E/ReactNativeJS: Module AppRegistry is not a registered callable module (calling runApplication)
02-09 11:18:39.007 13627-13646/com.productionbuild E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.productionbuild, PID: 13627
    com.facebook.react.common.JavascriptException: undefined is not a function (evaluating 'n.fill(255)'), stack:
    exports@527:162
    <unknown>@526:54
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@525:59
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@503:548
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@355:242
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@11:58
    _@2:1514
    d@2:897
    o@2:435
    global code@566:4
    
        at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
        at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:148)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
        at java.lang.Thread.run(Thread.java:818)

Code Example

import React, { Component } from "react";
import { Platform, StyleSheet, Text, View } from "react-native";
import "./shim.js";
import bitcoin from "bitcore-lib";
// import { Buffer } from "safe-buffer";
// var Buffer;
// if (typeof global !== "undefined") {
//   var Buffer = require("safe-buffer/").Buffer;
//   global.Buffer = Buffer; // TODO just use global Buffer
// }

type Props = {};
export default class App extends Component<Props> {
  constructor(props) {
    super(props);
    this.generateBitcoinKeys = this.generateBitcoinKeys.bind(this);
  }

  generateBitcoinKeys() {
    var privateKey = new bitcoin.PrivateKey(bitcoin.Networks.testnet);
    var publicKey = privateKey.toPublicKey();
    var address = publicKey.toAddress(bitcoin.Networks.testnet);
    return {
      Address: address.toString(),
      privateKey: privateKey.toString(),
      publicKey: publicKey.toString()
    };
  }
  render() {
    var aa = this.generateBitcoinKeys();
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>bitcoin address: {aa.Address}</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
  }
});

Environment

Platform: Android
React Native Environment Info:
System: Windows 10
CPU: x64 Intel(R) Core(TM) i5- CPU M 520 @ 2.40GHz 2.39 GHz

Binaries:
Node : 8.11.3
npm: 6.4.1

IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5014246
VS Code: 1.31.0
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.58.4 => 0.58.4
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions