React-native开发流程及问题整理

前端之家收集整理的这篇文章主要介绍了React-native开发流程及问题整理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

React-native开发流程及问题整理


关于React-native环境的搭建可也看这个:http://www.jb51.cc/article/p-fetlwczo-ym.html

运行react-native出现的问题:


1、找不到Android-23 ,确定你sdk里边的内容是最新的,包含5.0及以上。

2、插入多个usb设备会导致安装失败,拔掉只留一个就好。

可以查看设备状态:(确认adb已经配置到path里边)

  1. <pre name="code" class="java"><span style="font-size:18px;">$ adb devices
  2. List of devices attached
  3. emulator-5554 offline # Google emulator
  4. 14ed2fcc device # Physical device</span>


  1.  
3、安装成功以后显示:(白屏看下边解决办法)

如果启动程序出现白屏,那么就可能是一下几种情况:

(1)、若出现下边情况:

  1. dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
  2. Referenced from: /usr/local/bin/watchman
  3. Reason: image not found
  4.  
  5. dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
  6. Referenced from: /usr/local/bin/watchman
  7. Reason: image not found
  8.  
  9. Watchman: watchman--no-pretty get-sockname returned with exit code null dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
  10. Referenced from: /usr/local/bin/watchman
  11. Reason: image not found
  12.  
  13. ERROR watchman--no-pretty get-sockname returned with exit code null dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
  14. Referenced from: /usr/local/bin/watchman
  15. Reason: image not found
  16.  
  17. Error: watchman--no-pretty get-sockname returned with exit code null dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
  18. Referenced from: /usr/local/bin/watchman
  19. Reason: image not found
  20.  
  21. at ChildProcess.<anonymous> (/Users/Jing/Projects/ReactNative/AwesomeProject/node_modules/react-native/node_modules/sane/node_modules/fb-watchman/index.js:194:18)
  22. at emitTwo (events.js:87:13)
  23. at ChildProcess.emit (events.js:172:7)
  24. at maybeClose (internal/child_process.js:817:16)
  25. at Socket.<anonymous> (internal/child_process.js:319:11)
  26. at emitOne (events.js:77:13)
  27. at Socket.emit (events.js:169:7)
  28. at Pipe._onclose (net.js:469:12)

是pcre找不到,通过如下命令即可修复:

  1. $ brew uninstall pcre && brew install pcre
  1. 2)、如果带一次运行都没有显示 加载js的那个界面,一般是你的手机悬浮窗选项被禁用了,
  1. 开启就好
  1. 3)、如果实现加载js的界面,但是加载完以后还是白屏,没有显示welcome 。。。。。。的那个界面,那么说明还有问题
  1. Server 访问错误。参考官方文档。对于 Android 5.0 及以上的设备,直接运行:

  2. $ adb reverse tcp:8081 tcp:8081 
  3. 我找来一个 Android 5.0 的机器,果然可以了。对于 5.0 以下的机器,上面的命令会出错:

  4. $ adb reverse tcp:8081 tcp:8081 error: closed error: closed

  1. 4错误Couldnotget BatchedBridge,make sure your bundleispackaged correctly
  1. 错误具体原因不知道,但是可以解决,在项目的根目录下输入下边命令:
  1. react-native bundle --platform android --dev false --entry-fileindex.android.js --bundle-output android/app/src/main/assets/.android.bundle --sourcemap-output android/app/src/main/assets/.android.map--assets-dest android/app/src/main/res/
  1. 然后等命令执行完以后重新安装。

关于其中代码编写也就是他的开发流程介绍:

上边项目可以运行起来了,那么就可能进行接下来我们自己来编写的过程了:
首先我们要知道我们对于react-native开发基于的语言有了解,他是基于JavaScript,所以我们能想的到控件的编写,界面等等都是在js里边进行的
看下他里边的代码
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. * @flow
  5. */
  6.  
  7. import React,{ Component } from 'react';
  8. import {
  9. AppRegistry,StyleSheet,Text,View
  10. } from 'react-native';
  11.  
  12. class HelloWorld extends Component {
  13. render() {
  14. return (
  15. <View style={styles.container}>
  16. <Text style={styles.welcome}>
  17. Welcome to React Native!
  18. </Text>
  19. <Text style={styles.instructions}>
  20. To get started,edit index.android.js
  21. </Text>
  22. <Text style={styles.instructions}>
  23. Double tap R on your keyboard to reload,{'\n'}
  24. Shake or press menu button for dev menu
  25. </Text>
  26. </View>
  27. );
  28. }
  29. }
  30.  
  31. const styles = StyleSheet.create({
  32. container: {
  33. flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},welcome: {
  34. fontSize: 20,textAlign: 'center',margin: 10,instructions: {
  35. textAlign: 'center',color: '#333333',marginBottom: 5,});
  36.  
  37. AppRegistry.registerComponent('HelloWorld',() => HelloWorld);

里边包含了样式,还有显示的view的初始化已经设置文本内容

下边贴上我修改以后的效果界面

猜你在找的React相关文章