学习笔记——React Native配置

版权声明:转载请注明出处 https://blog.csdn.net/menwaiqingshan/article/details/81448421

原有项目嵌RN

配置的血泪史

一、0.49版本后没有了index.android.js和index.ios.js,统一为index.js。android目录下assets必须有index.android.bundle文件。

java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.

然后我在文件根目录下:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output
 app/src/main/assets/index.bundle --assets-dest app/src/main/res (最后发现我这语句也有错)

总结:出现这个报错应该是手机真机与npm 服务器没有连在同一个wifi下,然后包没有传过来。我上面的这个操作应该是手动把包通过usb安装的形式传了过去。

二、出现报错:

Unable to resolve module `AccessibilityInfo` from `E:\AndroidWorkSpace\MyApplication3\node_modules\react-native\Libraries\react-native\react-native-implementation.js`: Module `AccessibilityInfo` does not exist in the Haste module map

这个据说是0.56版本的问题,我把版本降到0.55就行了

语句: npm install [email protected]

三、再执行

react-native bundle --platform android --dev false --entry-file index.js --bundle-output
app/src/main/assets/index.bundle --assets-dest app/src/main/res (最后发现是我这语句也有错)

又遇到npm start不起来

npm ERR! missing script: start
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\CSY\AppData\Roaming\npm-cache\_logs\2018-08-06T02_33_06_055Z-debug.log


原因就是package.json中缺少start标签,因为之前react-native init 并没有生成这个标签 

 "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

四、还是报了我没有index.android.bundle文件。

原因我在asset文件生成的bundle文件是错误的,我生成的文件名是index.bundle。它一直说要的是index.android.bundle。啊啊啊,关键我还以为bundle文件android和ios之分也合并了。所以改一下生成的文件名。

终于!终于!hello world出现了!

五、后来发现index.android.bundle并没有必要一开始就放在AS的Assets文件夹里面(调试的时候)。

当真机和服务处于同一局域网,更新的时候会自己生成并下载到本地。

六、在AS项目中加依赖时报错

implementation 'com.facebook.react:react-native:0.55.4'

报错:

>* What went wrong:

Could not resolve all files for configuration ':app:debugCompileClasspath'.

Could not find com.facebook.react:react-native:0.55.4.

Searched in the following locations:

file:/D:/AndroidSDK/extras/m2repository/com/facebook/react/react-native/0.55.4/react-native-0.55.4.pom

我把依赖改成了implementation 'com.facebook.react:react-native:+'直接拉取最新的reactnative,然后再改成0.55.4就编译过了,不知道为什么

猜你喜欢

转载自blog.csdn.net/menwaiqingshan/article/details/81448421