• 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# 事务之SqlTransaction
    java获取字符串格式日期向前或向后n天的日期
    java中保留几位小数
    第一个androidAPP项目总结—ListView的上拉和下拉
    java中static作用详解
    第一个androidAPP项目总结—数据请求
    获取控件的高和宽
    Android学习笔记:如何设置ImageView中图片的显示方式
    TextView过长显示省略号, TextView文字中间加横线
    android中控件的使用
  • 原文地址:https://www.cnblogs.com/honeynm/p/9007072.html
Copyright © 2020-2023  润新知