无法从Windows上的资产index.android.bundle加载脚本

本文翻译自:Unable to load script from assets index.android.bundle on windows

I'm trying to run my first React Native project for first time on my device (Android 4.2.2). 我正在尝试在我的设备(Android 4.2.2)上首次运行我的第一个React Native项目。

And I get: 我得到:

unable to load script from assets index.android.bundle 无法从资产index.android.bundle加载脚本

Commands that I used: 我使用的命令:

  1. cd (project directory)
  2. react-native start
  3. react-native run-android

#1楼

参考:https://stackoom.com/question/30UZP/无法从Windows上的资产index-android-bundle加载脚本


#2楼

I've encountered the same issue while following the React Native tutorial (developing on Linux and targeting Android). 在遵循React Native 教程 (在Linux上开发并定位到Android)时,我遇到了相同的问题。

This issue helped me resolve the problem in following steps. 问题帮助我按照以下步骤解决了该问题。

  1. (in project directory) mkdir android/app/src/main/assets (在项目目录中) mkdir android/app/src/main/assets
  2. 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
  3. react-native run-android

You can automate the above steps by placing them in scripts part of package.json like this: 您可以通过将它们放在package.json scripts部分中来自动执行上述步骤,如下所示:

"android-linux": "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"

Then you can just execute npm run android-linux from your command line every time. 然后,您可以每次在命令行中执行npm run android-linux


#3楼

You can follow the instruction mentioned on the official page to fix this issue. 您可以按照官方页面上提到的说明解决此问题。 This issue occur on real device because the JS bundle is located on your development system and the app inside your real device is not aware of it's location. 由于JS捆绑包位于开发系统上,并且实际设备中的应用程序无法识别其位置,因此在实际设备上会发生此问题。


#4楼

OS: Windows 操作系统:Windows

Another way to resolve this problem after trying two methods above 尝试上述两种方法后,解决此问题的另一种方法
(because I installed SDK not in DEFAULT LOCATION like C:\\users\\"user_name"\\appdata\\local\\sdk ) (因为我没有在默认位置安装SDK ,例如C:\\ users \\“ user_name” \\ appdata \\ local \\ sdk

If you noticed that command line announced: "'adb' is not recognized as an internal or external command..." 如果您注意到命令行宣布:“'adb'不被识别为内部或外部命令...”

So this is how I get over: 所以这就是我克服的方式:
Examples: I installed SDK in D:\\Android\\sdk 示例:我在D:\\ Android \\ sdk中安装了SDK
So I will insert path in System Variables 2 more lines: 因此,我将在“系统变量”的另外2行中插入路径:

D:\Android\sdk\tools  
D:\Android\sdk\platform-tools  

(If you don't know how to edit path System Variables, here's the topic: https://android.stackexchange.com/questions/38321/what-do-i-type-in-path-variable-for-adb-server-to-start-from-cmd/38324 ) (如果您不知道如何编辑路径系统变量,则为以下主题: https : //android.stackexchange.com/questions/38321/what-do-i-type-in​​-path-variable-for-adb-服务器从cmd / 38324启动

Then I run cmd again: react-native run-android 然后我再次运行cmd: react-native run-android

It worked for me. 它为我工作。


#5楼

I have faced the same problem with a real android device. 我在真正的android设备上也遇到过同样的问题。

Solution: Based on this answer by Niltoid 解决方案:基于Niltoid的回答

  1. Find your local IP 查找您的本地IP
  2. Open app and shake your Android device 打开应用并摇动您的Android设备
  3. Go Dev Setting and>Debug Server... 进行开发设置并>调试服务器...
  4. Paste your IP and port; 粘贴您的IP和端口; XXXX:8088" (where X's are your local IP) XXXX:8088“(其中X是您的本地IP)

for Mac user: open your network preference, here you will get your local IP. 对于Mac用户:打开您的网络偏好设置,在这里您将获得本地IP。


#6楼

If when running react-native run-android command the second line of the trace is 如果在运行react-native run-android命令时,跟踪的第二行是

JS server not recognized, continuing with build...

it means packager for the app cannot be started and the app will fail to load without some extra steps. 这意味着该应用的打包程序无法启动,并且如果没有一些额外的步骤,该应用将无法加载。 Note that the end of the trace still reports success: 请注意,跟踪结束仍报告成功:

BUILD SUCCESSFUL

The problem is probably some port conflict (in my case it was the default IIS site that I completely forgot about). 问题可能是端口冲突(在我的情况下,这是我完全忘记的默认IIS站点)。 Another manifestation of the problem would be a failure to open http://localhost:8081/debugger-ui URL in Chrome. 该问题的另一种表现可能是无法在Chrome中打开http://localhost:8081/debugger-ui URL。

Once the port conflict is resolved the trace will report 解决端口冲突后,将报告跟踪

Starting JS server...

then an additional Node window will open ( node ...cli.js start ) and the app will load/reload successfully. 然后将打开另一个Node窗口( node ...cli.js start ),该应用程序将成功加载/重新加载。

After that you should be able to open debug console in Chrome with http://localhost:8081/debugger-ui . 之后,您应该可以使用http://localhost:8081/debugger-ui在Chrome中打开调试控制台。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值