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).
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
YourUserNamewith your username):Windows:
C:\\Users\\YourUserName\\AppData\\Local\\Android\\sdkMac:
/Users/YourUserName/Library/Android/sdkLinux:
/home/YourUserName/Android/SdkOn 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.jsonDepending on your target build (I assume
production) you want to define theANDROID_SDK_ROOTenvironmental variable for the target build underenvJSON key ineas.json. Theeas.jsonshould be in your react native project root folder - for example on the same level assrcor.expofolders usually are.Example
eas.jsonon Linux/Ubuntu:Change/keep
cliversion according to your project.