Unable to load script from assets’ index. Android. Bundle ‘
January 21, 2018 01:59:38 neuhenry reading: 1186
Copyright notice: This article is the original article of the blogger and cannot be reproduced without the permission of the blogger. https://blog.csdn.net/u010347226/article/details/79117940
Make sure your bundle is packaged correctly or you’re running a packer server. Here is a record of this
The author also checked the relevant solutions, but did not solve the problems I encountered. The solutions are as follows:
Step 1: first, cut to the root directory of our project, and then create a new assets folder in the Android/APP/SRC/main directory. You can execute the following commands in the terminal:
mkdir android/app/src/main/assets
1
Of course, it can also be created manually in Android studio
Step 2: we also need to execute the following command in the root directory of our project:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
1
Step 3: rerun the following command:
react-native run-android
1
However, this does not solve the above problem, and the error is still reported, and another problem will appear at this time
Cannot find entry file index.android.js in any of the roots: ["/Users/******/ReactNativeProjects/FirstReactApp"]
1
At this time, we went to the assets folder and found that the command in the second step did not generate the file we needed in the assets folder, and there was no file generated in it. At this time, the author continued to search and found a solution in stack overflow. Replace the command in the second step with the following 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
1
The original index.android.js has been changed to index.js. No wonder it can’t be found
after using the above command, two more files, index.android.bundle and index.android.bundle.meta, will appear in the assets folder
Run the project again, and finally a successful interface will appear
Summary: when you encounter a problem, you should dare to solve it and find out the cause of the problem. Here, index.android.bundle is a JS script used to call the system’s native controls. Every time you change index.js, you need to use the above command to update index.android.bundle in time, and then use the package to apply the new index.js, so when there is no index.android.bundle file, React native cannot run