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里边)
- <pre name="code" class="java"><span style="font-size:18px;">$ adb devices
- List of devices attached
- emulator-5554 offline # Google emulator
- 14ed2fcc device # Physical device</span>
3、安装成功以后显示:(白屏看下边解决办法)
如果启动程序出现白屏,那么就可能是一下几种情况:
(1)、若出现下边情况:
- dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
- Referenced from: /usr/local/bin/watchman
- Reason: image not found
- dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
- Referenced from: /usr/local/bin/watchman
- Reason: image not found
- Watchman: watchman--no-pretty get-sockname returned with exit code null dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
- Referenced from: /usr/local/bin/watchman
- Reason: image not found
- ERROR watchman--no-pretty get-sockname returned with exit code null dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
- Referenced from: /usr/local/bin/watchman
- Reason: image not found
- Error: watchman--no-pretty get-sockname returned with exit code null dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
- Referenced from: /usr/local/bin/watchman
- Reason: image not found
- at ChildProcess.<anonymous> (/Users/Jing/Projects/ReactNative/AwesomeProject/node_modules/react-native/node_modules/sane/node_modules/fb-watchman/index.js:194:18)
- at emitTwo (events.js:87:13)
- at ChildProcess.emit (events.js:172:7)
- at maybeClose (internal/child_process.js:817:16)
- at Socket.<anonymous> (internal/child_process.js:319:11)
- at emitOne (events.js:77:13)
- at Socket.emit (events.js:169:7)
- at Pipe._onclose (net.js:469:12)
是pcre找不到,通过如下命令即可修复:
- 4、错误Couldnotget BatchedBridge,make sure your bundleispackaged correctly
- 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/
- 然后等命令执行完以后重新安装。
关于其中代码编写也就是他的开发流程介绍:
上边项目可以运行起来了,那么就可能进行接下来我们自己来编写的过程了:
首先我们要知道我们对于react-native开发基于的语言有了解,他是基于JavaScript,所以我们能想的到控件的编写,界面等等都是在js里边进行的
看下他里边的代码:
- /**
- * Sample React Native App
- * https://github.com/facebook/react-native
- * @flow
- */
- import React,{ Component } from 'react';
- import {
- AppRegistry,StyleSheet,Text,View
- } from 'react-native';
- class HelloWorld extends Component {
- render() {
- return (
- <View style={styles.container}>
- <Text style={styles.welcome}>
- Welcome to React Native!
- </Text>
- <Text style={styles.instructions}>
- To get started,edit index.android.js
- </Text>
- <Text style={styles.instructions}>
- Double tap R on your keyboard to reload,{'\n'}
- Shake or press menu button for dev menu
- </Text>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},welcome: {
- fontSize: 20,textAlign: 'center',margin: 10,instructions: {
- textAlign: 'center',color: '#333333',marginBottom: 5,});
- AppRegistry.registerComponent('HelloWorld',() => HelloWorld);