react-native: Release APK crash immediately on launch - React Native ( Version 0.58.4)
🐛 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® Core™ 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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 25
- Comments: 41
Try to use
adb logcat *:E
, super helpful if the error is not JS relatedI’m getting these crashes with RN version 0.59.5 with APK, too. It works fine when building, but APK crashes right after opening the app. Can reproduce this on a real device (OnePlus 3, Android version 8.0.0), as well as on emulators (Pixel 3 XL with 64 bit Android 9.0 and Nexus 6P with Android 7.1.1). I can confirm that this is an issue even with a clean project created with react-native init. Other solutions mentioned here have not worked for me.
Disabling minification for release builds solved it for me:
def enableProguardInReleaseBuilds = false
This might help!!!
When the screen closes at start, there might be some errors not being showed in the build console. I don’t know why. So instead of running the react-native run-android, try tu run this:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
It will try to compile and it will start throwing the errors nobody was telling you!!It took me several hours to notice this, after knowing the errors, i fixed one by one. Hope it helps!!
Some of the silly errors that were closing the app just after starts:
@jassumgoran, this is already false. Not working.
I am having the same issue. RN version 0.60. Solved when I set enableProguardInReleaseBuilds to false.
I have resolved this issue by using JSC build scripts for Android. Thanks to jsc-android.
Upgrading from RN 0.59.5 to RN 0.59.10 worked for me.
I am facing the same problem with RN 0.59.4. After installing react-native-admob and changing some dependencies I can compile but not run the app. But I can’t use even in debug. What I should check ? This problem occours affter instaling and linking admob lib.
Any ideas ? plz…
Sorry for late reply. Its working both in emulator as well as in production build (real device). For this you have to install JSC build scripts for Android. You must use version r15c to build. r17 and above break NDK build that this app requires. Download the r15c NDK version here: https://developer.android.com/ndk/downloads/older_releases.
and follow the installation requirements for JSC build scripts for Android. After installation and path setup i have made following changes in Android/build.gradle:
allprojects { repositories { mavenLocal() jcenter() google() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url “$rootDir/…/node_modules/react-native/android” } maven { // Local Maven repo containing AARs with JSC library built for Android url “$rootDir/…/node_modules/jsc-android/android” } maven { url “https://jitpack.io” } maven { url “https://maven.google.com” } } }
and in Android i have made following changes in android/app/build.gradle
project.ext.react = [ entryFile: “index.js” ]
apply from: “…/…/node_modules/react-native/react.gradle”
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion
applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versionCodes = [“armeabi-v7a”:1, “x86”:2] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
dependencies { implementation fileTree(dir: “libs”, include: [“*.jar”]) implementation “com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}” implementation “com.facebook.react:react-native:+” // From node_modules }
configurations.all { resolutionStrategy { force ‘org.webkit:android-jsc:r216113’ } } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into ‘libs’ }
I hope this will help you. Thanks
@ank26oct It just works in emulator, not in real device. Could you post your solution here?
@quietbits Seems to be related to https://github.com/facebook/react-native/issues/24260
the same, any solution for help me!!
I have the exact same issue and the same dependencies (versions). All works good in debug builds but release builds are crashing: