加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 08:25:25 所属栏目:百科 来源:网络整理
导读:React-native开发流程及问题整理 关于React-native环境的搭建可也看这个:http://www.jb51.cc/article/p-fetlwczo-ym.html 运行react-native出现的问题: 1、找不到Android-23 ,确定你sdk里边的内容是最新的,包含5.0及以上。 2、插入多个usb设备会导致安装

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


关于React-native环境的搭建可也看这个:http://www.52php.cn/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找不到,通过如下命令即可修复:

$ brew uninstall pcre && brew install pcre 
	(2)、如果带一次运行都没有显示   加载js的那个界面,一般是你的手机悬浮窗选项被禁用了,
开启就好
	(3)、如果实现加载js的界面,但是加载完以后还是白屏,没有显示welcome 。。。。。。的那个界面,那么说明还有问题

是 Server 访问错误。参考官方文档。对于 Android 5.0 及以上的设备,直接运行:

$ adb reverse tcp:8081 tcp:8081 

我找来一个 Android 5.0 的机器,果然可以了。对于 5.0 以下的机器,上面的命令会出错:

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

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 中文版文档
上边项目可以运行起来了,那么就可能进行接下来我们自己来编写的过程了:
首先我们要知道我们对于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);

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读