android ReactNative之Cannot find entry file index.android.js in any of the roots
2018年04月02日 14:53:12

阅读数:85

由于公司要求,想让我去了解一下ReactNative开发,说是为了以后开发的以后方便移植到IOS上。晕!!!没办法,照着React Native的中文开发文档配置环境https://reactnative.cn/docs/0.51/getting-started.html#content,配置过程还算简单,以为很简单,其实还是我太单纯。照着文档创建项目,创建好后运行项目,坑出现了,这个坑我埋了半天的时间,真是太耽误时间了。遇到的其实别的博客上都有说,Cannot find entry file index.android.js in any of the roots,就是这个错误日志,按照其他的博客的解答方式我一一尝试,不幸无一能解决我的问题,反而使用了他们的方案衍生出其他的error日志,是我本来离答案很近又被扯远了,我连续创建了三个项目才将问题解决,在此记录,为人填坑。

在react native以前的版本,index.android.js与index.ios.js是分开的两个文件,在最新版本中这两个文件合并成index.js一个文件了。但是如果你在创建项目之后直接运行,肯定会报Cannot find entry file index.android.js in any of the roots这种类似的错误,因为在根目录下已经不存在index.anroid.js和index.ios.js这两个文件,所以肯定不会检索到,你更改App.js的内容后更不可能生效。

我解决的方式是:创建项目时

react-native init AwesomeProject
cd AwesomeProject
执行完这两个命令后,不要直接去运行,先执行以下命令去创建assets目录:


通过执行
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/
命令会在assets目录下生成两个文件


控制器会提示生成成功

 这个时候你再运行react-native run-android,就不会报错了,完美运行。你可以测试一下,通过更改App.js的样式,然后重新reload,样式就会及时生效。

纯是个人经过4、5个小时尝试的方法,真实有效,欢迎来怼。

方法二:
2down voteaccepted

Changed the version of react project to a lower one from here

npm install -g rninit

rninit init [Project Name] --source react-native@0.40.0

Worked okay for both on both iOS and Android on . If you get Error Could not get BatchedBridge. run this

adb reverse tcp:8081 tcp:8081

This worked for me.

android ReactNative之Cannot find entry file index.android.js in any of the roots的更多相关文章

  1. Cannot find entry file index.android.js in any of the roots:[ Android ]

    Changed the version of react project to a lower one from here npm install -g rninit rninit init [Pro ...

  2. 项目初始化以后出现:Unable to load script from assets 'index.android.bundle

    Mac中真机测试React Native project时出现Unable to load script from assets 'index.android.bundle' 2018年01月21日 ...

  3. React-Native 之 index.android.bundle

    问题: index.android.bundle  这个bug 我相信很少同学会遇到,然而就是这个问题,困扰了我跟我的同事多天, 各种方法处理:  进入 android 目录  ./gradlew c ...

  4. 解决React Native unable to load script from assets index.android.bundle on windows

    React Native运行的时候,经常碰到React Native unable to load script from assets index.android.bundle on windows ...

  5. React Native: unable to load scripts from assets 'index.android.bundle' on real device

    问题:重新建了一个项目后,运行react-native run-android报: unable to load scripts from assets 'index.android.bundle' ...

  6. Unable to load script from assets 'index.android.bundle'.make sure you bundle is packaged correctly

    解决此问题 以下方法每次都需要执行命令2才能更新 1.创建assets目录 mkdir android/app/src/main/assets 2.执行命令 react-native bundle - ...

  7. react native中Unable to load script from assets 'index.android.bundle'解决方案

    刚刚朋友问我,说是创建好一个项目,运行后报错:Unable to load script from assets 'index.android.bundle',以前好好的没出现这种现象,于是我找到一个 ...

  8. Unable to load script from assets 'index.android.bundle' 出错?

    野路子太多,坑人真的!F**k 言归正传,当你运行 react native 程序的时候出现这个错误 ,如果您使用Windows,请按以下方式运行命令,或者如果出现错误“无法找到条目文件index.a ...

  9. React-Native开发之原生模块封装(Android)升级版

     本文主题:如何实现原生代码的复用,即如何将原生模块封装. (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/52862 ...

随机推荐

  1. 请问C#中string是值传递还是引用传递?

    https://www.cnblogs.com/xiangniu/archive/2011/08/17/2143486.html 学了这么久,终于弄明白了... 是引用传递 但是string又有值传递 ...

  2. BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 WOPI和新的Office Web Apps Server

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序  WOPI和新的Office Web Apps Server ...

  3. 工作流JBPM_day02:1-回顾_2-设计流程Transition

    工作流JBPM_day02:1-回顾 1,工作流框架 处理流程的 流程多,有变化 2,准备环境 + HelloWorld 一.概念 Deployment部署对象 ProcessDefinition 流 ...

  4. Messages: No result defined for action cn.itcast.oa.test.TestAction and result SUCCESS

    Struts Problem Report Struts has detected an unhandled exception: Messages: No result defined for ac ...

  5. lua知识点整理

    1. lua全局环境和局部环境 local cf = loadstring(" local i=0 i=i+1 print(i) ") --从后面两个输出我们可以看出,生成的函数的 ...

  6. C++中的抽象基类示例

    抽象基类(abstract base class,ABC)例子:圆与椭圆.建立一个基类BaseEllipse,建立它的恋歌继承了Ellipse和Circle.ellipse.h #ifndef ELL ...

  7. ubuntu14.04 LTS 搜狗输入法安装和不能输入中文的解决方法

    搜狗输入法安装 1.首先通过Ubuntu软件中心,需要安装:fcitx https://pinyin.sogou.com/linux/help.php 2.然后再安装搜狗输入法包 https://pi ...

  8. Resin任意文件读取漏洞

    Resin是什么 虽然看不上但是还是原因下百度百科: Resin是CAUCHO公司的产品,是一个非常流行的支持servlets和jsp的引擎,速度非常快.Resin本身包含了一个支持HTTP/1.1的 ...

  9. Sublime Less 自动编译成css

    1.note编译 .下载notejs https://nodejs.org/en/ .首先你要安装lessc.我是用npm包管理器直接安装的,只需要一条命令,如下: npm install less ...

  10. 使用as3crypto在Flex中实现AES加密

    要在Flex中实现AES加密,可以通过as3crypto实现.但是as3crypto本身的用法比较复杂,一般是封装一下再调用. 下面是9RIA上的一篇文章给出的一个实现,使用中稍感不方便(见注释): ...