APK errors

SDK location not found

Error text

SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file.

Cause

Gradle does not know where the Android SDK is. local.properties is missing or ANDROID_HOME is not set.

Step-by-step fix

  1. Create a local.properties file in the project root.
  2. Put an sdk.dir= line with the full path of the SDK folder in it.
  3. In a terminal also set ANDROID_HOME and add platform-tools to PATH.
  4. If the SDK folder does not exist, install it with Android Studio's SDK Manager or use sdkmanager.
  5. After changing it, run ./gradlew --stop and build again.

Example commands

# local.properties (git-ə qoyma)
sdk.dir=/home/user/Android/Sdk
# Windows: sdk.dir=C\:\\Users\\user\\AppData\\Local\\Android\\Sdk
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin

How to prevent it

local.properties belongs to one computer. List it in .gitignore and never commit it.

Author and license: Nibras Code