androidreact-nativeexpoexpo-buildexpo-eas

Expo build EAS - local - SDK location not found


When I used the new build tool from expo called EAS to build my react native application locally:
eas build --platform android --local
I got an error:

SDK location not found. Define location with an ANDROID_SDK_ROOT

All the answers I've found are suggesting creating file local.properties in an android directory and setting the sdk.dir in it, this is however related to the old build tool expo build... another option is to simply define the environmental variable on the system level which I tried to avoid.

So I was wondering how to do it in some type of configuration file still local to the react native project. I found the answer by accident, so I'm sharing the knowledge below 👇

By the way, if you're looking for where is the default build path of the final bundle - it's most likely dumped into the project root (don't forget to refresh files if you need to).


Solution

  • TL;DR

    Project root eas.json => build => production => "env": { "ANDROID_SDK_ROOT": "/path/to/AndroidSDK" }

    Step 1: find path to your Android SDK

    The problem in general is that the EAS build is missing path to Android SDK, so first you need to find the correct path,
    Android SDK does not have to be in the default path
    but if you have it in one of the following, you can take it and jump to step 2 (replace YourUserName with your username):
    Windows: C:\\Users\\YourUserName\\AppData\\Local\\Android\\sdk
    Mac: /Users/YourUserName/Library/Android/sdk
    Linux: /home/YourUserName/Android/Sdk

    On some systems, the paths may be case-sensitive => copy them as-they-are from system

    I personally for example have SDK on a bigger HDD elswhere. Don't know the path but still have Android Studio? => try looking for "Android SDK" in "System Settings" in settings/configuration - Configure => Settings => Appearance & Behavior (or maybe you have it under Preferences). Don't have Android Studio anymore/path there is not valid? => you're left with brute force searching for "android*" in folders like "tools", "build-tools", "emulator", but you may be better off with just installing the SDK into a new location :-)

    Step 2: configure in eas.json

    Depending on your target build (I assume production ) you want to define the ANDROID_SDK_ROOT environmental variable for the target build under env JSON key in eas.json. The eas.json should be in your react native project root folder - for example on the same level as src or .expo folders usually are.

    Example eas.json on Linux/Ubuntu:

    {
      "cli": {
        "version": ">= 0.49.0"
      },
      "build": {
        "development": {
          "developmentClient": true,
          "distribution": "internal"
        },
        "preview": {
          "distribution": "internal"
        },
        "production": {
            "env": {
                "ANDROID_SDK_ROOT": "/home/YourUserName/Android/Sdk"
            }
        }
      },
      "submit": {
        "production": {}
      }
    }
    

    Change/keep cli version according to your project.