react-native: Trying to upgrade to support android 12 but getting - Unable to load script, make sure your bundle "index.android.bundle" is packaged correctly for release.
New Version
0.66.5+
Old Version
0.63.4
Build Target(s)
Android Emulator and release build as well
Output of react-native info
System: OS: macOS 12.6.1 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Memory: 170.70 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.14.0 - /usr/local/bin/node Yarn: Not Found npm: 8.3.1 - /usr/local/bin/npm Watchman: 2022.10.03.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.2 - /Users/kapil.raghuwanshi/.sdkman/candidates/java/current/bin/javac npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 17.0.2 react-native: 0.63.4 => 0.66.5 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Issue and Reproduction Steps
We are trying to migrate our react native project in order to support android 12.
https://reactnative.dev/blog/2021/09/01/preparing-your-app-for-iOS-15-and-android-12
We are struggling to resolve this issue past few days.
We searched on the internet https://stackoverflow.com/questions/55441230/unable-to-load-script-make-sure-you-are-either-running-a-metro-server-or-that-yo/58570426#58570426
and found a few solutions below:
-
adb reverse tcp:8081 tcp:8081
-
setting port and host configs
-
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
Out of which all are working fine in our local system and emulators but once we create a release build for the production environment, no luck with any of such hacks.
Since my final package was built using below react native bundle command but gets installed on the separate native android project. There it is still the same issue.
“react-native bundle --platform android --dev true --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./server/dir/”
Could you please help us out in resolving this issue?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (1 by maintainers)
Yes, sometimes you have to do this for development, but that shouldn’t be the case for release build.
@kapilraghuwanshi Based on the RN version (0.66~) that you provide, you should be using
com.android.tools.build:gradle:4.2.2
instead. https://github.com/react-native-community/rn-diff-purge/blob/version/0.66.5/RnDiffApp/android/build.gradleI strongly advise you to use the Gradle version that comes with your current RN version, or else you might face some build issues as I mentioned earlier. Or I highly recommend you spend some time upgrading the RN version which supports a much higher Gradle version, you also get better support for the latest Android/iOS.
Trust me, I literally face the exact same issue few days ago, where I accidentally change the Gradle version via Android studio.
let me give this a try.
From what I have tested on the fresh RN 0.70.6 project, both the dev & release build work fine, at least for me. @kapilraghuwanshi Is it possible for you to create a small example project that can reproduce this problem?
I just tried it out with a different project setup. It works fine until launching in an emulator with API level 31, regardless of gradle / react native version.
RN v 0.70.6 + gradle 7.2.1 leads to this error message, RN v 0.66.1 + gradle 4.2.2 also leads to this error message
but only on devices with API > 31 (Android 12)