Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir

created 2021/09/27updated 2021/09/27

エラー

bash
Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * 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/user/your-app/android/local.properties'.

というWarningが発生し、React NativeのビルドがFAILEDになっていた。

解決策

.zshrcなどにANDROID_SDK_ROOTを定義するかlocal.propertiesファイルを作成し、sdk.dirを定義する。今回は、local.propertiesを作成する方で対応した。

bash
touch /Users/user/your-app/android/local.properties
local.properties
## This file must *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. #Thu Dec 10 16:26:54 JST 2020 sdk.dir=/Users/user/Library/Android/sdk

参考

android - Where is android_sdk_root? and how do I set it.? - Stack Overflow