1# Guide to set up Java/SDK/NDK for Android 2 3Follow this doc if you haven't set up Java/SDK/NDK for Android development 4already. 5This doc provides a CLI tutorial to set them up. Otherwise, you can do the same 6thing with Android Studio GUI. 7 8## Set up Java 17 91. Download the archive from Oracle website. 10Make sure you have read and agree with the terms and conditions from the website before downloading. 11```bash 12export DEV_HOME=<path-to-dev> 13cd $DEV_HOME 14``` 15Linux: 16```bash 17curl https://download.oracle.com/java/17/archive/jdk-17.0.10_linux-x64_bin.tar.gz -o jdk-17.0.10.tar.gz 18``` 19macOS: 20```bash 21curl https://download.oracle.com/java/17/archive/jdk-17.0.10_macos-aarch64_bin.tar.gz -o jdk-17.0.10.tar.gz 22``` 232. Unzip the archive. The directory named `jdk-17.0.10` is the Java root directory. 24```bash 25tar xf jdk-17.0.10.tar.gz 26``` 273. Set `JAVA_HOME` and update `PATH`. 28 29Linux: 30```bash 31export JAVA_HOME="$DEV_HOME"/jdk-17.0.10 32export PATH="$JAVA_HOME/bin:$PATH" 33``` 34macOS: 35```bash 36export JAVA_HOME="$DEV_HOME"/jdk-17.0.10.jdk/Contents/Home 37export PATH="$JAVA_HOME/bin:$PATH" 38``` 39 40Note: Oracle has tutorials for installing Java on 41[Linux](https://docs.oracle.com/en/java/javase/17/install/installation-jdk-linux-platforms.html#GUID-4A6BD592-1840-4BB4-A758-4CD49E9EE88B) 42and [macOS](https://docs.oracle.com/en/java/javase/17/install/installation-jdk-macos.html#GUID-E8A251B6-D9A9-4276-ABC8-CC0DAD62EA33). 43Some Linux distributions has JDK package in package manager. For example, Debian users can install 44openjdk-17-jdk package. 45 46## Set up Android SDK/NDK 47Android has a command line tool [sdkmanager](https://developer.android.com/tools/sdkmanager) which 48helps users managing SDK and other tools related to Android development. 49 501. Go to https://developer.android.com/studio and download the archive from "Command line tools 51only" section. Make sure you have read and agree with the terms and conditions from the website. 52 53Linux: 54```bash 55curl https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -o commandlinetools.zip 56``` 57macOS: 58```bash 59curl https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip -o commandlinetools.zip 60``` 612. Unzip. 62```bash 63unzip commandlinetools.zip 64``` 653. Specify a root for Android SDK. For example, we can put it under `$DEV_HOME/sdk`. 66 67``` 68mkdir -p $DEV_HOME/sdk 69export ANDROID_HOME="$(realpath $DEV_HOME/sdk)" 70# Install SDK 34 71./cmdline-tools/bin/sdkmanager --sdk_root="${ANDROID_HOME}" --install "platforms;android-34" 72# Install NDK 73./cmdline-tools/bin/sdkmanager --sdk_root="${ANDROID_HOME}" --install "ndk;26.3.11579264" 74# The NDK root is then under `ndk/<version>`. 75export ANDROID_NDK="$ANDROID_HOME/ndk/26.3.11579264" 76``` 77 78### (Optional) Android Studio Setup 79If you want to use Android Studio and never set up Java/SDK/NDK before, or if 80you use the newly installed ones, follow these steps to set Android Studio to use 81them. 82 83Copy these output paths to be used by Android Studio 84```bash 85echo $ANDROID_HOME 86echo $ANDROID_NDK 87echo $JAVA_HOME 88``` 89 90Open a project in Android Studio. In Project Structure (File -> Project 91Structure, or `⌘;`) -> SDK Location, 92* Set Android SDK Location to the path of $ANDROID_HOME 93* Set Android NDK Location to the path of $ANDROID_NDK 94* Set JDK location (Click Gradle Settings link) -> Gradle JDK -> Add JDK... to the path of $JAVA_HOME 95