前端之家收集整理的这篇文章主要介绍了
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 环境变量:
$ ls –al .bash_profile(.bash_profile为隐藏文件,因此要用ls –a命令查找)
$vi .bash_profile(用vi编辑.bash_profile)
$ 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
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
import NavigationExperimental from 'react-native-deprecated-custom-components';
并将NavigationExperimental.Navigator替换Navigator
5: Android NDK 下载后的bin文件Mac下解压方法:
chmod a+x android-ndk-r10c-darwin-x86_64.bin
./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>