Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release APK fails immediately on launch (Version 0.54) #18357

Closed
hardnett opened this issue Mar 13, 2018 · 68 comments
Closed

Release APK fails immediately on launch (Version 0.54) #18357

hardnett opened this issue Mar 13, 2018 · 68 comments
Labels
Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@hardnett
Copy link

hardnett commented Mar 13, 2018

I have a web view app that is very straightforward. The iOS version is running perfectly. The android version runs perfectly in debug mode using the package server. However, the release version of the apk crashes immediately when launched.

The errors I am getting from logcat are:

03-12 22:12:07.665 16051-16068/? E/AndroidRuntime: FATAL EXCEPTION: Thread-2
                                                   Process: com.gtcworx, PID: 16051
                                                   java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
                                                       at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:33)
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:234)
                                                       at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1113)
                                                       at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:113)
                                                       at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:920)
                                                       at java.lang.Thread.run(Thread.java:764)
03-12 22:12:07.789 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.videos-fSpP8T16jLfLPEk3Hl3pmw==/base.apk
03-12 22:12:07.790 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.videos-fSpP8T16jLfLPEk3Hl3pmw==/base.apk
03-12 22:12:07.790 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.videos-fSpP8T16jLfLPEk3Hl3pmw==/base.apk
03-12 22:12:07.794 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.apps.docs.editors.slides-9EEF5YDNu3OKNBNwayfu9g==/base.apk
03-12 22:12:07.794 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.apps.docs.editors.slides-9EEF5YDNu3OKNBNwayfu9g==/base.apk
03-12 22:12:07.794 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.apps.docs.editors.slides-9EEF5YDNu3OKNBNwayfu9g==/base.apk
03-12 22:12:07.795 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.contacts-2KRJls5awi4KQQ6cjkUQQA==/base.apk
03-12 22:12:07.795 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.contacts-2KRJls5awi4KQQ6cjkUQQA==/base.apk
03-12 22:12:07.797 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.dialer-1BN26SkEVNcra4NPGyK-nA==/base.apk
03-12 22:12:07.797 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.dialer-1BN26SkEVNcra4NPGyK-nA==/base.apk
03-12 22:12:07.797 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.dialer-1BN26SkEVNcra4NPGyK-nA==/base.apk
03-12 22:12:07.798 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.799 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.799 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.799 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.800 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.805 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk

since this does not use the package server, I figured the problem is that the bundle is packaged incorrectly. However, I am not sure that I can do to fix the way the package is bundled.

I did some searches and noticed that this problem is caused the View.propTypes references. I followed the steps to see if there were any such references in my modules and there are not. There are only comments referring to the issue and explaining the patches put into place.

I also found an article that suggested I check the name of the app in the index.js file and compare that with the name in the MainActivity. I checked those and they are identical. I also checked my package.json for the same name.

I have also done several cleans of the project using Gradle.

Thanks for any help that can be provided.

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 8.8.1
  Yarn: 1.3.2
  npm: 5.4.2
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
  react: ^16.2.0 => 16.2.0
  react-native: ^0.54.2 => 0.54.2

Expected Behavior

I expected the app to launch and show the website in the webView.

I am unable to reproduce the error in snack, but here is the link that shows how it should work: https://snack.expo.io/r1JzDYSFG

Actual Behavior

dialog box shows up saying "app has stopped" and ask to open again.

Steps to Reproduce

  1. Create a web view app
  2. Build it using the versions of the libs I have above
  3. Generate a signed release apk
  4. Install release apk onto device
  5. Run the app
@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like your issue may refer to an older version of React Native. Can you reproduce the issue on the latest stable release?

Thank you for your contributions.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Old Version ⏪ Ran Commands One of our bots successfully processed a command. labels Mar 13, 2018
@Lxxyx
Copy link
Contributor

Lxxyx commented Mar 13, 2018

How did you pack the release version of App?
May be still running at dev mode?

@hardnett
Copy link
Author

Im using Android Studio to generate the release version of the app. Its taking me through the same steps that I have using for Java-based Android apps without problems.

@alexmbp
Copy link

alexmbp commented Mar 13, 2018

Have the same issue. I'm using Build -> Generate signing APK in android studio.
But I'm using "react-native": "0.54.0"

@hardnett
Copy link
Author

I just updated to 0.54 which actually took me to 0.54.2 and I have the same result.

my new react-native info dump:

Environment:
OS: macOS High Sierra 10.13.3
Node: 8.8.1
Yarn: 1.3.2
npm: 5.4.2
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: ^16.2.0 => 16.2.0
react-native: ^0.54.2 => 0.54.2

@hardnett hardnett changed the title Release APK fails immediately on launch (Version 0.53) Release APK fails immediately on launch (Version 0.54) Mar 13, 2018
@alexmbp
Copy link

alexmbp commented Mar 13, 2018

Well. It's working with
react-native run-android --variant=release
and with ./gradlew assembleRelease and configuring signing.
Also I've updated gradle and should set android.enableAapt2=false.
Probably issue connected with gradle update.

@hardnett
Copy link
Author

hardnett commented Mar 13, 2018

Thanks that definitely worked. I did not use the --variant=release, but the command-line process works fine. It may be gradle, but it appears that Android Studio is using the same commands. Thanks for your help @alexmbp

@abrajeethan
Copy link

This issue is still present! However the fix is setting android.enableAapt2=false and the using "Generate signed APK" command. If react-native is boasting of supporting both frameworks then they should take care of announcing these issue fixes too.

@hardnett
Copy link
Author

Wow. I’ll

@hardnett hardnett reopened this Mar 16, 2018
@hardnett
Copy link
Author

Sorry. Hit the wrong button. I’m reopening this until it’s fixed.

@deepeshkarkee
Copy link

Please note! RN 0.54.0 - 0.54.2 has issue with fetch call. It returns Blob, instead of returning the InitBody as string. I suggest you downgrade your RN to any version between 0.51 to 0.53

@doertli
Copy link

doertli commented Mar 29, 2018

@deepeshkarkee do you know if RN 0.55 RC has fixed the fetch issues?

@deepeshkarkee
Copy link

@doertli: I haven't tried RN0.55 RC.
I am thinking of avoiding reactive native upgrade until they release .60 or a stable release of the series.
Reason: they are planning to deprecate ComponentWillMount(), and are suggesting to use CompinentDidMount().

@hramos hramos removed the Platform: macOS Building on macOS. label Mar 29, 2018
@puckey
Copy link

puckey commented May 1, 2018

Experiencing the same issue with RN 0.55.3

@wedneyyuri
Copy link

I'm using version 0.55.4 and it's not working, currently using a hacky workaround to use Android Studio:

  • cd android && ./gradlew assembleRelease (create the bundle)
  • Android Studio -> Build -> Generate Signed APK (generate a signed apk)

Another option is generating signed apks using command line as suggested by @alexmbp. This procedure is described here.

@gderaco
Copy link

gderaco commented Jun 19, 2018

Add this lines

project.ext.react = [
        entryFile: "index.js",
        bundleAssetName: "index.android.bundle",
        bundleInAlpha: true,
        bundleInBeta: true
]

before
apply from: "../../node_modules/react-native/react.gradle" in build.gradle

@hramos hramos added Platform: Android Android applications. and removed 📋No Repro Steps labels Jun 28, 2018
@arambrosius
Copy link

I am having the same issue. Works fine in debug but once I release the APK it crashes on load. Here are my packages.
"dependencies": {

	"axios": "^0.18.0",
	"react": "16.4.1",
	"react-native": "0.55.4",
	"react-native-elements": "^0.19.1",
	"react-native-material-dropdown": "^0.11.1",
	"react-native-push-notification": "^3.0.2",
	"react-native-swipeout": "^2.3.3",
	"react-native-vector-icons": "^4.6.0",
	"react-navigation": "^2.6.2",
	"react-redux": "^5.0.7",
	"redux": "^4.0.0",
	"redux-axios-middleware": "^4.0.0",
	"redux-thunk": "^2.3.0",
	"round-to": "^3.0.0"
},
"devDependencies": {
	"babel-jest": "23.2.0",
	"babel-preset-react-native": "^4.0.0",
	"jest": "23.3.0",
	"react-test-renderer": "16.4.1"
},
"jest": {
	"preset": "react-native"
}

I see info on downgrading react-native but nothing has worked for me. My app is in production and need help asap. Any ideas?

@sacchykhedkar
Copy link

Add this lines

project.ext.react = [
        entryFile: "index.js",
        bundleAssetName: "index.android.bundle",
        bundleInAlpha: true,
        bundleInBeta: true
]

before
apply from: "../../node_modules/react-native/react.gradle" in build.gradle

@sacchykhedkar
Copy link

Thank you very man it helps me lot, its save my day

@alvelig
Copy link

alvelig commented Feb 3, 2019

The fix is upgrading RN to 0.57.4 or downgrading gradle to 3.1.4.

For those who want a really neat workaround without having to upgrade/downgrade:
app/build.gradle:

project.ext.react = [
    entryFile: "index.js",
    jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/mergeReleaseAssets/out"
]

@LeoUrushi
Copy link

I’m having the same problem but my react native and gradle versions seem newer.
Thanks for all the suggestions.
So far, I’ve tried the methods suggested by @bhardman1986 , @gderaco + @sacchykhedkar and @alvelig so far with no success.
Has anyone found a solution for this in newer versions?

My environment:
package.json

"react": "^16.6.3",
"react-dom": "^16.8.1",
"react-native": "0.58.4",
"react-native-gesture-handler": "^1.0.15",
"react-native-image-pan-zoom": "^2.1.11",
"react-navigation": "^3.2.1"

android/ build.gradle

buildscript {
ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'

}

}

@jordanb
Copy link

jordanb commented Feb 26, 2019

Root cause well explained here --> #18357 (comment), thanks @jsaraiva

"react-native": "0.58.5" with com.android.tools.build:gradle:3.3.0 is also a working combination if you want to use a newer version of gradle.

Thanks everyone for your help, it was painful to face this issue.

@ShokiiCookiie
Copy link

ShokiiCookiie commented Mar 8, 2019

Still having this issue with "react-native": "0.58.6" and com.android.tools.build:gradle:3.3.0 downgrading to com.android.tools.build:gradle:3.1.4 fixed it for me.

@chardnett
Copy link

This is still an issue apparently. Which is amazing.

@mpalmerlee
Copy link

mpalmerlee commented Mar 17, 2019

I've been using RN 0.57.4 and gradle 3.2+ up to this point without any issues. I recently added productFlavors for different environments for testing (dev, stage, prod, etc...) and hit this same issue. If I downgrade to gradle 3.1.4 then my release build works fine, so @ShokiiCookiie it's possible that you are hitting this issue due to RN's handling of gradle 3.2+ directories when using productFlavors in your build.gradle file.

Here is some more information on how to repro:
in app/build.gradle

    flavorDimensions "env"
    productFlavors {
        dev {
            dimension "env"
            applicationIdSuffix ".dev"
        }
        stage {
            dimension "env"
            applicationIdSuffix ".stage"
        }
        prod {
            dimension "env"
        }
    }

Build on a device for release using one of the flavors:
./gradlew installStageRelease

With com.android.tools.build:gradle:3.2.1 I get an immediate crash opening the app (the same bundling error: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server. com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets if I use com.android.tools.build:gradle:3.1.4 it works like a charm.

@frysukarto
Copy link

i have same trouble.
apps can running at another device but not oppo. how can i handle this?

@ShokiiCookiie
Copy link

@mpalmerlee Yes I'm using productFlavors.
Still facing this with "react-native": "0.59.3" 😩

@gangilanoop
Copy link

Any update on this issue ?

@nadirHomeFriend
Copy link

The fix is upgrading RN to 0.57.4 or downgrading gradle to 3.1.4.

For those who want a really neat workaround without having to upgrade/downgrade:
app/build.gradle:

project.ext.react = [
    entryFile: "index.js",
    jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/mergeReleaseAssets/out"
]

hello, it is not working for me , help plz

@firebluetom
Copy link

Facing same issue. Using latest RN 59 and gradle 3.4, works in debug mode but on --variant=release it just crashes.

@gauravsbagul
Copy link

does anybody has any solution on this please... we all are having same issue i followed all the steps but build still fails and i get same error "Task 'installRelease' not found in project ':app'. Some candidates are: 'uninstallRelease'"
Microsoft Windows [Version 10.0.17134.706]
(c) 2018 Microsoft Corporation. All rights reserved.
----->
E:\Developement**>react-native run-android --variant=release
info Starting JS server...
info Building and installing the app on the device (cd android && gradlew.bat app:installRelease)...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

  • What went wrong:
    Task 'installRelease' not found in project ':app'. Some candidates are: 'uninstallRelease'.

  • Try:
    Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 41s
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installRelease. Run CLI with --verbose flag for more details.

@jhchong92
Copy link

does anybody has any solution on this please... we all are having same issue i followed all the steps but build still fails and i get same error "Task 'installRelease' not found in project ':app'. Some candidates are: 'uninstallRelease'"
Microsoft Windows [Version 10.0.17134.706]
(c) 2018 Microsoft Corporation. All rights reserved.
----->
E:\Developement******>react-native run-android --variant=release
info Starting JS server...
info Building and installing the app on the device (cd android && gradlew.bat app:installRelease)...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

  • What went wrong:
    Task 'installRelease' not found in project ':app'. Some candidates are: 'uninstallRelease'.
  • Try:
    Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 41s
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installRelease. Run CLI with --verbose flag for more details.

@gauravsbagul I have faced this before the fix was to setup signingConfigs for your buildType

signingConfigs {
        release {
            Properties properties = new Properties()
            properties.load(project.rootProject.file('local.properties').newDataInputStream())
            storeFile file(properties.getProperty('APP_RELEASE_STORE_FILE'))
            keyAlias properties.getProperty('APP_RELEASE_KEY_ALIAS')
            storePassword properties.getProperty('APP_RELEASE_STORE_PASSWORD')
            keyPassword properties.getProperty('APP_RELEASE_KEY_PASSWORD')

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

@jhchong92
Copy link

Downgrading to 3.1.4 for gradle fixed the problem for me.. finally.. lost a lot of hair on this. As @mpalmerlee mentioned, upgrading to newer versions of react native didn't resolve this if you're using productFlavors. In my case, I was using RN 0.57.4

@Bvida100
Copy link

Bvida100 commented May 7, 2019

I had same problem with android 3.4.0 and gradle 5.4.1, I downgrade to android 3.3 and gradle 4.10.1 and the issue is gone. I use React Native 0.59.5.

@remarcus
Copy link

remarcus commented May 13, 2019

I can confirm versions that @Bvida100 stated.

For beginners or confused how to downgrade you can do that in following config files:

android/gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

and

android/build.gradle:

dependencies {
...
    classpath 'com.android.tools.build:gradle:3.3.0'

Best to do that from Android Studio by opening android solution. It should prompt to sync gradle, do that and sync should be successful.

@thib92
Copy link
Contributor

thib92 commented May 19, 2019

@remarcus looks like the best answer to me.

t-nanava pushed a commit to microsoft/react-native-macos that referenced this issue Jun 17, 2019
…ebook#21409)

Summary:
Android Gradle Plugin 3.2 uses a new intermediates/merged_assets directory instead of intermediates/assets. This workaround copies the javascript bundle to both directories for compatibility purposes.

Fixes facebook#21132
Fixes facebook#18357
Pull Request resolved: facebook#21409

Differential Revision: D10141860

Pulled By: hramos

fbshipit-source-id: 0fb20fcec67ec2bfd7a8d9052599bbc70464b466
@taeminpak
Copy link

I have tried upgrading to versions suggested by @remarcus and @thib92 and am still finding the app crash on launch (for release versions only).
My RN version is "0.57.4".
I am following these directions to generate the release APK: https://medium.com/@impaachu/react-native-android-release-build-crash-on-device-14f2c9eacf18
I have also tried generating the release APK through Android Studio, but I get the same result.
Anyone have any suggestions?
Also does anyone know if using AndroidX has any effect on the release build process?

@remarcus
Copy link

remarcus commented Jun 27, 2019

@taeminpak I believe there were a lot of changes since 0.57.4 and even some breaking ones with the releases of 0.58 and 0.59.

If possible you could try RN v0.59.9, because it has support for more recent build tools. If not I would suggest retrieving logs from device running release version of your app and the issue might not be connected to this one.

Regarding AndroidX recent release of Google Play Services has impacted some libraries that were using its latest version (i.e. react-native-device-info), but that's unlikely because it would probably crash on build first.

I also had some issues in the past regarding drawables and not having asset of required density so app would crash.

Would suggest you to create a new fresh project and add your current dependencies to see if problem is actually in current build tools and RN version.

You could also take a look at RN Changelog to see if something has been fixed with newer versions. It's always like playing cat and mouse unfortunately.

Good luck! :)

@taeminpak
Copy link

@remarcus
could you elaborate on your issues regarding 'drawables and not having asset of required density'?

@StarkAndy
Copy link

Please check your render() function and see if your are using any Component which been deprecated checking by commenting each one of them one by one .Hope it might help

@facebook facebook locked as resolved and limited conversation to collaborators Oct 2, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 2, 2019
KusStar pushed a commit to KusStar/react-native that referenced this issue Nov 11, 2020
…ebook#21409)

Summary:
Android Gradle Plugin 3.2 uses a new intermediates/merged_assets directory instead of intermediates/assets. This workaround copies the javascript bundle to both directories for compatibility purposes.

Fixes facebook#21132
Fixes facebook#18357
Pull Request resolved: facebook#21409

Differential Revision: D10141860

Pulled By: hramos

fbshipit-source-id: 0fb20fcec67ec2bfd7a8d9052599bbc70464b466
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests