在本机的sdk等环境配置无问题,成功构建过项目的情况下,从github上clone一个新的RN项目。尝试本地运行的时候报错。

从github上clone的RN项目,在本地运行react-native run-android的时候,会报错:

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/getting-started.html

Github上克隆ReactNative项目报错:Could not install the app on the device

解决方法

第一步:用AndroidStudio构建项目

网上有很多建议新建local.properties等,实际上,AndroidStudio会帮忙做这些事。

用AndroidStudio打开项目的android文件夹

Github上克隆ReactNative项目报错:Could not install the app on the device

等待项目构建完毕后,会发现项目中多了一些文件

                           Github上克隆ReactNative项目报错:Could not install the app on the device

第二步:配置运行权限 

如果配置环境后不可以运行 可能是无权限运行。在项目下运行:

chmod 755 android/gradlew

就是为android文件夹下的gradlew命令添加权限 

这一步网上的攻略很少提到,导致我在这个地方坑了很久

运行项目

完成上面两步,基本就可以在模拟器/真机上运行项目了

react-native run-android

 

相关文章: