【问题】在mac 中运行react native android app 项目,结果出现 Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081的错误,完整错误如下
【完整错误】
- What went wrong: Could not determine the dependencies of task ':app:installDebug'.
SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/zhiyahan/AndroidStudioProjects/Rainbow/cloudcash/android/local.properties'.
-
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
-
Get more help at help.gradle.org
BUILD FAILED in 9s
error Failed to install the app. Make sure you have the Android development environment set up: reactnative.dev/docs/enviro…. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
【分析】
由于项目是先在window系统上运行的,后来在mac 系统上运行,由于sdk的位置差异化,造成window上开发的代码,在mac 无法自动变sdk的路径。
【解决方案】
需要在mac 上的android studio 先打开项目,自动生成local.propeties 文件,配置mac下的sdk路径后,在执行run-android 命令方可。
sdk.dir=/Users/***/Library/Android/sdk