React Native 开发中遇到的问题

前端之家收集整理的这篇文章主要介绍了React Native 开发中遇到的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1:当在项目目录下运行Flow命令报错:
Wrong version of Flow. The config specifies version ^0.45.0 but this is version 0.49.0 Could not start Flow server!
解决办法:
运行如下命令: npm install flow-bin@0.45.0 -g
2: 运行Androd版本时遇到
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME
environment variable.

解决办法:
设置Android sdk 环境变量:
方法一:
$ cd (进入用户登陆目录)
$ ls –al .bash_profile(.bash_profile为隐藏文件,因此要用ls –a命令查找)
$vi .bash_profile(用vi编辑.bash_profile)
方法二:
$ cd (进入用户登陆目录)
$ touch .bash_profile
$open -e .bash_profile
将Android sdk设置加入 .bash_profile 中:
export ANDROID_HOME=/Users/scofield/Library/Developer/Xamarin/android-sdk-macosx/
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
验证是否配置成功:
运行adb -version命令
Android Debug Bridge version 1.0.31
运行 $android
会打开Android SDK Manager窗口
3:运行run命令时报:
Packager can't listen on port 8081
解决办法:
首先找出哪些应用在使用8081端口
运行命令: lsof -i :8081
删除相关进程:kill pid
4: React-Native到0.44版本后Navigator 不能用的问题
Navigator is deprecated and has been removed from this package. It can now be installed and imp orted from react-native-deprecated-custom-components instead of react-native. Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html
解决办法:
1.在项目根目录下运行如下命令:
npm install react-native-deprecated-custom-components --save
2:在js文件中加入
import NavigationExperimental from 'react-native-deprecated-custom-components';
并将NavigationExperimental.Navigator替换Navigator
5: Android NDK 下载后的bin文件Mac下解压方法
1.获取文件权限
chmod a+x android-ndk-r10c-darwin-x86_64.bin
2. 解压出文件

./android-ndk-r10c-darwin-x86_64.bin

6:在调用this.setState()方法时报 undefined is not a function ( evaluating setState)

需要将点击事件方法申明 this.onPress = this.onPress.bind(this);或者在点击事件中写成

onPress={this.onPress.bind(this)}

7:在start packager时出现:Packager cann't listen on port 8081

是由于之前启动的Packager还在运行,所以需要关闭它。

首先查看哪些进程在占用8081端口

lsof -i :8081

然后shut down the other process

kill -9 PID

Packager can't listen on port 8081
React Native Packager
3:32:03 PM
Most likely another process is already using this port
React Native Packager
Run the following command to find out which process:
lsof -i :8081
Then,you can either shut down the other process:
kill -9 <PID>

8: 运行程序时,遇到异常如下异常:

一般有两种情况:

(1)not register it in index.android.js / index.ios.js or name is wrong

default class Test extends Component
AppRegistry.registerComponent('Test',() => Test);

(2) 打开了多个终端,都在运行同个App. 需要按照问题七的方法去kill掉其他的进程

9: IOS真机测试运行的时候遇到如下问题:


1.mac电脑设置了防火墙 ------解决方案,在系统设置里关闭防火墙
2.node或者npm的版本有问题------解决方案,全部更新至最新的版本

3:Mac的IP地址会自动变动

解决方案,将jsCodeLocation做相应的调整,jsCodeLocation = [NSURL URLWithString:@"http://192.168.206.27:8081/index.ios.bundle?platform=ios&dev=true"];

4:还有一个就是iOS9的网络访问问题

解决方案,Xcode项目的plist文件里已经有App Transport Security Settings,关键是默认的设置是只允许localhost访问不允许别的访问,那么就得修改下这儿

10:iOS真机运行时报如下错误

是由于Identification.h文件没有相应的.m文件

11: 导入第三方库在import时会出现如下错误

Lexical or Preprocessor Issue 'xxx.h' file not found

网上各种方法都尝试了还是不行,最后直接把第三方库拖入Library中解决问题,如下:

原文链接:https://www.f2er.com/react/303594.html

猜你在找的React相关文章