zoukankan      html  css  js  c++  java
  • android ReactNative之Cannot find entry file index.android.js in any of the roots

    android ReactNative之Cannot find entry file index.android.js in any of the roots

    由于公司要求,想让我去了解一下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.

  • 相关阅读:
    c++ 为自定义类添加stl遍历器风格的遍历方式
    C++ 生成随机数
    c/c++ 函数说明以及技巧总结
    XSLT 教程
    C# 高效过滤DataTable 中重复数据方法
    xml获取指定节点的路径
    TreeView控件
    推荐一些C#相关的网站、资源和书籍
    C#多线程操作
    C#二进制序列化
  • 原文地址:https://www.cnblogs.com/honeynm/p/9007072.html
Copyright © 2011-2022 走看看