1、github上clone下来的react native 项目,在mac上 react-native run-android
后,报错如下:
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
按照网上所有的方法,检查了安卓的安装环境,java的安装环境,也没有解决问题,最终在Github上找到了解决方案:
Could not install the app on the device, read the error above for details
即
//1.在app的根目录下运行
chmod 755 android/gradlew
//2.然后再运行就正常了
react-native run-android
2、在React Native中使用fetch时,返回的数据如下图:
请求代码如下:
fetch(url)
.then(response => {
console.log(response)
})
结果一直拿不到正常的body对象,而实际应该返回的数据放在了_bodyInit
和_bodyInit
里面,一直找不到原因,后来逛Stack Overflow才发现原因,
也就是应该在第一个then
时return response.json()
,然后在下一个then时才能拿到结果。
代码如下:
fetch(url)
.then(response => {
return response.json()
})
.then(responseData => {
console.log(responseData)
})