React-native: When i used the command npx react-native run-android --variant=release the app crash, but on debug mode its working fine

Created on 11 Nov 2020  路  6Comments  路  Source: facebook/react-native

Description:

so i am trying to install my app with npx react-native run-android --variant=release to test it before i put it in the store and when its finish the app crash immedly!

React Native version:

System:
OS: Windows 10 10.0.18363
CPU: (8) x64 Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Memory: 4.59 GB / 15.69 GB
Binaries:
Node: 14.2.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - ~AppData\Roaming\npm\yarn.CMD
npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK:
API Levels: 23, 27, 28, 29
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.2
System Images: android-29 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
Android NDK: 21.3.6528147
Windows SDK: Not Found
IDEs:
Android Studio: Version 4.1.0.0 AI-201.8743.12.41.6858069
Visual Studio: Not Found
Languages:
Java: 1.8.0_211
Python: 3.9.0
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.1 => 17.0.1
react-native: 0.63.3 => 0.63.3
react-native-windows: Not Found
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. npx react-native run-android --variant=release reproduce the issue.
  2. on mac its working fine from some reason.

Expected Results

run the app in release mode on device without crash on start

package.json:

{
"name": "xxx",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@material-ui/core": "^4.11.0",
"@react-native-community/art": "^1.2.0",
"@react-native-community/async-storage": "^1.11.0",
"@react-native-community/datetimepicker": "^3.0.4",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-community/push-notification-ios": "^1.7.1",
"@react-native-firebase/analytics": "^7.6.9",
"@react-native-firebase/app": "^8.4.7",
"@react-native-firebase/crashlytics": "^8.4.12",
"@react-native-firebase/messaging": "^7.9.2",
"@twotalltotems/react-native-otp-input": "^1.3.11",
"axios": "^0.21.0",
"chance": "^1.1.7",
"lottie-ios": "^3.1.9",
"lottie-react-native": "^3.5.0",
"moment": "^2.29.1",
"prop-types": "^15.7.2",
"react": "17.0.1",
"react-native": "0.63.3",
"react-native-action-sheet": "^2.2.0",
"react-native-animatable": "^1.3.3",
"react-native-animated-loader": "^0.0.8",
"react-native-check-box": "^2.1.7",
"react-native-confirmation-code-field": "^6.5.1",
"react-native-contacts": "^5.2.3",
"react-native-copilot": "^2.5.1",
"react-native-exit-app": "^1.1.0",
"react-native-fast-image": "^8.3.3",
"react-native-gesture-handler": "^1.8.0",
"react-native-indicators": "^0.17.0",
"react-native-keyboard-aware-scroll-view": "^0.9.3",
"react-native-localization": "^2.1.6",
"react-native-material-menu": "^1.1.3",
"react-native-material-ripple": "^0.9.1",
"react-native-modal": "^11.5.6",
"react-native-otp-verify": "^1.0.3",
"react-native-permissions": "^2.2.2",
"react-native-pie": "^1.1.2",
"react-native-popup-dialog": "^0.18.3",
"react-native-push-notification": "^6.1.2",
"react-native-ratings": "^7.3.0",
"react-native-reanimated": "^1.13.1",
"react-native-restart": "^0.0.17",
"react-native-safe-area-context": "^3.1.8",
"react-native-screens": "2.12.0",
"react-native-select-contact": "hazesoftco/react-native-select-contact",
"react-native-simple-radio-button": "^2.7.4",
"react-native-svg": "^12.1.0",
"react-native-vector-icons": "^7.1.0",
"react-native-version-number": "^0.3.6",
"react-native-webview": "^10.10.0",
"react-navigation": "^4.4.3",
"react-navigation-drawer": "^2.6.0",
"react-navigation-material-bottom-tabs": "^2.3.3",
"react-navigation-stack": "^2.10.0",
"react-navigation-tabs": "^2.10.1",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"sprintf-js": "^1.1.2"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/runtime": "^7.12.1",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.2",
"eslint": "^7.12.1",
"jest": "^26.6.2",
"metro-react-native-babel-preset": "^0.63.0",
"react-native-svg-transformer": "^0.14.3",
"react-test-renderer": "17.0.1"
},
"jest": {
"preset": "react-native"
}
}

app/build.gradle

 apply plugin: "com.android.application"

  import com.android.build.OutputFile



  project.ext.react = [
    entryFile   : "index.js",
    enableHermes: false,  // clean and rebuild if changing
 ]

apply from: "../../node_modules/react-native/react.gradle"


def enableSeparateBuildPerCPUArchitecture = true


def enableProguardInReleaseBuilds = true


def jscFlavor = 'org.webkit:android-jsc:+'


def enableHermes = project.ext.react.get("enableHermes", false);

android {
compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

dexOptions {
    javaMaxHeapSize "4g"
}
defaultConfig {
    applicationId "xxx.xxx.xxx"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 515
    versionName "515"
    multiDexEnabled true
    ndkVersion "21.3.6528147"
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}
configurations.all {
    resolutionStrategy {
        force "com.facebook.soloader:soloader:0.8.0"
    }
}
signingConfigs {
    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
        }
    }
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {

        signingConfig signingConfigs.release
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}

applicationVariants.all { variant ->
    variant.outputs.each { output ->

        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 {
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation "com.facebook.react:react-native:+"  // From node_modules
     implementation 'androidx.multidex:multidex:2.0.1'  // <-- ADD THIS DEPENDENCY
    implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
    implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01'


  if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }
}


task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
 }
 apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); 
applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

build.gradle

 buildscript {
  ext {
    buildToolsVersion = "29.0.2"
    minSdkVersion = 16
    compileSdkVersion = 29
           targetSdkVersion = 29

   }
  repositories {
    google()
    jcenter()

  }
  dependencies {
    classpath 'com.android.tools.build:gradle:4.1.1'
    classpath 'com.google.gms:google-services:4.3.4'
    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
   }
 }

  allprojects {
  repositories {
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url("$rootDir/../node_modules/react-native/android")
    }

    maven {
        // Android JSC is installed from npm
        url("$rootDir/../node_modules/jsc-android/dist")
    }

    google()
    jcenter()
    maven { url 'https://jitpack.io'}
       maven { url  "https://sdk.smartlook.com/android/release"}


  }
 }
 apply plugin: 'com.google.gms.google-services'

Android log:

2020-11-11 10:00:27.675 25619-25662/? E/unknown:ReactNative: ReactInstanceManager.createReactContext: mJSIModulePackage null
2020-11-11 10:00:27.675 25619-25666/? E/ReactNativeJNI: logMarker CREATE_REACT_CONTEXT_END
2020-11-11 10:00:27.679 25619-25662/? E/unknown:DisabledDevSupportManager: Caught exception
java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run '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.loadScriptFromAssets(Unknown Source:2)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(Unknown Source:10)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(Unknown Source:18)
at d.c.m.r.q(Unknown Source:264)
at d.c.m.r.c(Unknown Source:0)
at d.c.m.r$e.run(Unknown Source:68)
at java.lang.Thread.run(Thread.java:764)
2020-11-11 10:00:27.680 3308-5173/? E/BufferQueueProducer: [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity[5474]#0] disconnect: not connected (req=1)
2020-11-11 10:00:27.686 25619-25662/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: xxx.xxx.xxx, PID: 25619
java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run '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.loadScriptFromAssets(Unknown Source:2)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(Unknown Source:10)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(Unknown Source:18)
at d.c.m.r.q(Unknown Source:264)
at d.c.m.r.c(Unknown Source:0)
at d.c.m.r$e.run(Unknown Source:68)
at java.lang.Thread.run(Thread.java:764)
2020-11-11 10:00:27.690 3831-5823/? E/WindowManager: win=Window{1fe4fa5 u0 com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm.WindowManagerService.tryStartExitingAnimation:2790 com.android.server.wm.WindowManagerService.relayoutWindow:2488 com.android.server.wm.Session.relayoutForTranslate:302 android.view.IWindowSession$Stub.onTransact:518 com.android.server.wm.Session.onTransact:186 android.os.Binder.execTransact:739
2020-11-11 10:00:27.969 3831-3929/? E/WindowManager: win=Window{a7a8f5e u0 Splash Screen xxx.xxx.xxxEXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.AppWindowToken.destroySurfaces:870 com.android.server.wm.AppWindowToken.destroySurfaces:851 com.android.server.wm.WindowState.onExitAnimationDone:5443 com.android.server.wm.WindowStateAnimator.onAnimationFinished:319 com.android.server.wm.WindowState.onAnimationFinished:5865 com.android.server.wm.-$$Lambda$yVRF8YoeNdTa8GR1wDStVsHu8xM.run:2 com.android.server.wm.SurfaceAnimator.lambda$getFinishedCallback$0:97
2020-11-11 10:00:28.031 25689-25689/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2020-11-11 10:00:28.032 25689-25689/? E/Zygote: accessInfo : 1
2020-11-11 10:00:28.043 25689-25689/? E/ng.android.loo: Not starting debugger since process cannot load the jdwp agent.
2020-11-11 10:00:28.061 13842-13899/? E/PBSessionCacheImpl: sessionId[60879364885567770] not persisted.
2020-11-11 10:00:28.111 3831-3997/? E/InputDispatcher: channel 'c0514be xxx.xxx.xxx/xxx.xxx.xxx.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

Needs Android

Most helpful comment

I found out that the index.android.bundle was not packaged with the generated .apk file. Reverting back to React Native's used gradle version (com.android.tools.build:gradle:3.5.3) is wat it fixed for me.

All 6 comments

+1

i have this problem too.

This happens to me aswel. If i build older releases now, that previously worked before, it still crashes. So im kind of scared that this lies beyond React-Native.

I found out that the index.android.bundle was not packaged with the generated .apk file. Reverting back to React Native's used gradle version (com.android.tools.build:gradle:3.5.3) is wat it fixed for me.

@wilbo thanks thats helped me !

i have a similar problem with the index.android.bundle, solved it running this command first:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

Was this page helpful?
0 / 5 - 0 ratings