The android version runs perfectly in debug mode using android studio emulator. However, the release version of the apk crashes immediately when launched.
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
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)
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
}
});
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
I have the exact same issue and the same dependencies (versions). All works good in debug builds but release builds are crashing:
2019-02-10 12:22:53.475 9442-9482/? E/ReactNativeJS: Module AppRegistry is not a registered callable module (calling runApplication)
2019-02-10 12:22:53.486 9442-9483/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.borntoinvest.borntoinvest, PID: 9442
com.facebook.react.common.c: null is not an object (evaluating 'P.MARKET'), stack:
<unknown>@408:287
_@2:1514
d@2:967
o@2:435
<unknown>@406:3622
_@2:1514
d@2:967
o@2:435
<unknown>@382:167
_@2:1514
d@2:967
o@2:435
<unknown>@380:152
_@2:1514
d@2:967
o@2:435
<unknown>@355:216
_@2:1514
d@2:967
o@2:435
<unknown>@11:58
_@2:1514
d@2:897
o@2:435
global code@643:4
at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(Unknown Source:20)
at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(Unknown Source:0)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:148)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:21)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
at android.os.Looper.loop(Looper.java:166)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(Unknown Source:16)
at java.lang.Thread.run(Thread.java:784)
Disabling minification for release builds solved it for me:
def enableProguardInReleaseBuilds = false
@jassumgoran, this is already false. Not working.
I have resolved this issue by using JSC build scripts for Android. Thanks to jsc-android.
@ank26oct: Hi, I have the same issue, also since I upgraded to 0.58.x (from 0.57.3). But I have it on iOS, haven't tried Android yet. Does it work for you on iOS? Could you elaborate on the fix / what needs to be changed exactly?
Same as you. Looking forward a correct solution.
Just upgraded from 0.58.4 to 0.58.5, still the same issue unfortunately.
I have resolved this issue by using JSC build scripts for Android.
React Native 0.59 will embed that JSC version, so unless someone can post a repro that uses 0.59 (meaning, a project init-ed to 0.59rc2 that still create the crash) there is no need to keep this open.
Moreover, it really seems that it has something to do with the libraries you add, not React Native itself.
Again, if you can post a repro for 0.59* I'll re-open.
@ank26oct Do you know what exact library causes this problem?
I've been debugging for hours, I have no clue what's causing it.
@ank26oct It just works in emulator, not in real device. Could you post your solution here?
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
defaultConfig {
applicationId "com.abbc"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
multiDexEnabled true
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
}
packagingOptions {
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
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
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.
dependencies {
implementation (project(':react-native-admob')){
exclude group: "com.google.android.gms", module: "play-services-ads"
}
implementation project(':react-native-vector-icons')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.google.firebase:firebase-auth:16.2.1"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.google.firebase:firebase-core:16.0.8"
implementation ("com.google.android.gms:play-services-ads:17.0.0") {
force = true;
}
}
Any ideas ? plz...
I'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.
@quietbits Seems to be related to https://github.com/facebook/react-native/issues/24260
Posting this here as well in the other related issue. Here is a repo with APK to try: https://github.com/quietbits/react-native-apk-crash. Any tests are much appreciated!
I am having the same issue. RN version 0.57.8
solved when I moved from 0.59.0-rc.0 to 0.59.8
https://medium.com/@impaachu/react-native-android-release-build-crash-on-device-14f2c9eacf18 this post fixed my issue, but I skipped some steps.
I found this issue #24261 with Hi-Pri tag.
after generating the keystore run the following command
"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"
this worked for me
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:
Try to use adb logcat *:E
, super helpful if the error is not JS related
I am having the same issue. RN version 0.60.
Solved when I set enableProguardInReleaseBuilds to false.
This resolved my issue.
@azharuddinkhan8898 its not working
@chilugen Use this adb logcat *:E
and check what error you are getting when you open your app.
@azharuddinkhan8898
Upgrading from RN 0.59.5 to RN 0.59.10 worked for me.
@ShaneMatthias me to 0.57.5 to 0.59.10 and this link https://react-native-community.github.io/upgrade-helper/?from=0.57.5&to=0.59.10
Updated to 0.59.10 but still not working just apk crash on start. I've tried every workaround but nothing any suggestion?
delete node_modules folder reinstall npm i @LeonardoPlacanica
Already tried at least 10 times. The app is building the release correctly but once i run the apk on a device it crashes at the start
@LeonardoPlacanica some android folder code plz
build.gradle on root project
`// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.3.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "27.0.0"
}
}`
build.gradle in app folder
`apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
react-native bundle
with the correct arguments during the Android buildapply from: "../../node_modules/react-native/react.gradle"
line.project.ext.react = [
entryFile: "index.js",
bundleAssetName: "index.android.bundle",
bundleInAlpha: true,
bundleInBeta: true,
// whether to bundle JS and assets in debug mode
bundleInDebug: false,
// whether to bundle JS and assets in release mode
bundleInRelease: true,
// the root of your RN project, i.e. where "package.json" lives
root: "../../"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
/**
android {
lintOptions {
checkReleaseBuilds false
}
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.medallioniosapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
packagingOptions {
exclude 'META-INF/androidx.exifinterface_exifinterface.version'
}
// applicationVariants are e.g. debug, release
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, "arm64-v8a": 3, "x86_64": 4]
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
}
}
}
}
dependencies {
compile (project(':react-native-camera')) {
exclude group: "com.android.support"
}
implementation "com.android.support:exifinterface:+"
implementation "com.android.support:support-annotations:+"
implementation "com.android.support:support-v4:+"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
// For animated GIF support
compile 'com.facebook.fresco:animated-gif:1.10.0'
implementation "com.google.android.gms:play-services-gcm:12.+"
compile project(':react-native-fetch-blob')
}
// 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'
}
`
Already tried at least 10 times. The app is building the release correctly but once i run the apk on a device it crashes at the start
the same, any solution for help me!!
Please try to use try catch in your function when you use another service
I'm facing this after install react-native-firebase. This happens only on Android 8.0 by now.
Disabling minification for release builds solved it for me:
def enableProguardInReleaseBuilds = false
Thank you! It works for me! 馃帀
Try to use
adb logcat *:E
, super helpful if the error is not JS related
best tip ever !
I could see that
E/AndroidRuntime(18795): FATAL EXCEPTION: AsyncTask #4
E/AndroidRuntime(18795): Process: com.myapp, PID: 18795
E/AndroidRuntime(18795): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(18795): at android.os.AsyncTask$3.done(AsyncTask.java:304)
E/AndroidRuntime(18795): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
E/AndroidRuntime(18795): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
E/AndroidRuntime(18795): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E/AndroidRuntime(18795): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime(18795): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime(18795): at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime(18795): Caused by: java.lang.SecurityException: Neither user 10116 nor current process has android.permission.READ_PROFILE.
E/AndroidRuntime(18795): at android.os.Parcel.readException(Parcel.java:1546)
E/AndroidRuntime(18795): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
E/AndroidRuntime(18795): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
E/AndroidRuntime(18795): at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
E/AndroidRuntime(18795): at android.content.ContentResolver.query(ContentResolver.java:489)
E/AndroidRuntime(18795): at android.content.ContentResolver.query(ContentResolver.java:433)
E/AndroidRuntime(18795): at com.rt2zz.reactnativecontacts.ContactsProvider.getContacts(ContactsProvider.java:212)
E/AndroidRuntime(18795): at com.rt2zz.reactnativecontacts.ContactsManager$1.doInBackground(ContactsManager.java:101)
E/AndroidRuntime(18795): at com.rt2zz.reactnativecontacts.ContactsManager$1.doInBackground(ContactsManager.java:94)
E/AndroidRuntime(18795): at android.os.AsyncTask$2.call(AsyncTask.java:292)
E/AndroidRuntime(18795): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
adding then <uses-permission android:name="android.permission.READ_PROFILE"/>
to my AndroidManifest.xlm
solved my problem
Most helpful comment
Try to use
adb logcat *:E
, super helpful if the error is not JS related