记录使用vscode运行reactnative项目遇到的问题

1,424 阅读1分钟

1、把创建好react native项目,使用VS code打开,在android文件下的local.properties写上sdk的路径

2、在终端-新建终端,在终端执行 react-native start命令

报react-native : 无法加载文件 C:\Users\admin\AppData\Roaming\npm\react-native.ps1,因为在此系统上禁止运行脚本 错误,这是因为权限问题导致的

解决方法:找到powershell,使用管理员权限运行,然后输入set-ExecutionPolicy RemoteSigned ,然后选择Y 或者A ,就好了

3、输入adb connect 127.0.0.1:62001 连接夜神模拟器,运行后以下日志表示模拟器连接成功

4、然后输入 react-native run-android运行项目

很遗憾没有成功,报以下错误:

Failed to install the following Android SDK packages as some licences have not been accepted.   build-tools;28.0.2 Android SDK Build-Tools 28.0.2 To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager. Alternatively, to transfer the license agreements from one workstation to another, see d.android.com/r/studio-ui…

解决方法: 找到SDK目录tools/bin下,在cmd窗口输入sdkmanager.bat --licenses命令,下面提示全部选择y即同意即可 这表示同意sdk所有证书许可授权

5、然后在输入react-native run-android运行,历经各种问题终于项目启动起来了