Reputation: 340
Currently, I have completed updating my project to React-Native 0.70.6 (The Latest). Everything is working as expected during development (npm run android) and Apk builds process also generates APK without any error. But when I run my Final APK app suddenly crashes without any error. To detect the reason for crash I have used several debugging tools. Which gives me the error as shown below
java.lang.RuntimeException: Unable to load script.
Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFr assets(CatalystInstanceImpl.java:248)
at com.facebook.react.bridge.JSBundleLoader $1.loadScript(JSBundleLoader.java:29)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundl e(CatalystInstanceImpl.java:277)
at com.facebook.react.ReactInstanceManager.createReactCont ext(ReactInstanceManager.java:1402)
at com.facebook.react.ReactInstanceManager.access $1200(ReactInstanceManager.java:136)
at com.facebook.react.ReactInstanceManager
$5.run(ReactInstanceManager.java:1108) at java.lang.Thread.run(Thread.java:818)
I searched everywhere about this problem on the web. I read several posts and got several suggestions that I have implemented in my files.
My android/build.gradle file :
buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
if (System.properties['os.arch'] == "aarch64") {
ndkVersion = "24.0.8215888"
} else {
ndkVersion = "21.4.7075529"
}
googlePlayServicesAuthVersion = "19.2.0"
firebaseMessagingVersion = "21.1.0"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
classpath 'com.google.gms:google-services:4.3.14'
}
}
allprojects {
repositories {
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
mavenCentral {
content {
excludeGroup "com.facebook.react"
}
}
google()
maven { url 'https://www.jitpack.io' }
}
}
Few configurations of android/app/build.gradle
// other code .....
project.ext.react = [
enableHermes: true,
entryFile: "index.js",
bundleAssetName: "index.android.bundle",
bundleInDebug: true,
bundleInRelease: true
]
def enableSeparateBuildPerCPUArchitecture = true
def enableProguardInReleaseBuilds = true
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
multiDexEnabled true
if (isNewArchitectureEnabled()) {
// We configure the CMake build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
cmake {
arguments "-DPROJECT_BUILD_DIR=$buildDir",
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
"-DANDROID_STL=c++_shared"
}
}
if (!enableSeparateBuildPerCPUArchitecture) {
ndk {
abiFilters (*reactNativeArchitectures())
}
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include (*reactNativeArchitectures())
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// other code ......
}
Detail of java I am using
Openjdk version "18.0.1.1" 2022-04-22
OpenJDK Runtime Environment Homebrew (build 18.0.1.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.1.1+0, mixed mode, sharing)
I have tried creating a fully new project on react native 0.70.6 and generated a signed apk which worked fine but didn't work with dependencies.
Upvotes: 3
Views: 1018
Reputation: 275
I had similar problem. Downgrade gradle helps me in my case.
In: android/gradle/wrapper/gradle-wrapper.properties
i changed version from 7.5.1
to 7.3.3
.
In: android/build.gradle
i changed gradle from : classpath("com.android.tools.build:gradle:7.2.1")
to
classpath("com.android.tools.build:gradle:7.1.1")
Upvotes: 4