react-native: unable to load script from assets index.android.bundle - React Native
🐛 Bug Report
I am trying to create the native react app by learning some tutorials and using react-native-cli. I am getting this error while running the application on android platform using react-native run-androidscript. The error I am getting is unable to load script from assets index.android.bundle. Make sure your build is packaged correctly and you are running a packager server. I tried setting port for TCP. After reading a lot of articles here I found this solution by running the 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 && react-native run-android
So I added this command in my package.json. Now every time I have to run this command for the changes in code, live refreshing is not working and as I have seen in many tutorial that a development server will start but nothing is starting. I still didn’t understand why this error occurs and why not a JS development server is starting ?
Here is the info of react version - react-native-cli: 2.0.1 react-native: 0.58.6
To Reproduce
Create a native app using react-native-cli
Expected Behavior
Should run app and development server
Code Example
Environment
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15
Highly recommend to take account this answer - https://stackoverflow.com/a/53326616: for 28 api-level (
Starting with Android 9.0 (API level 28), cleartext support is disabled by default.
)Turns out I should pay more attention and read the release notes! 😂 😅 I was able to fix my issue by using gradle 3.1 as recommended in the react native release notes for 0.57.
In my project I modified /android/build.gradle and changed
classpath 'com.android.tools.build:gradle:3.3.2'
to
classpath 'com.android.tools.build:gradle:3.1.4'
Once that was done I tried building my app on a device again and everything worked as expected!
This issue helped me A LOT to understand what was happening - https://github.com/Microsoft/react-native-code-push/issues/1427#issuecomment-430913598