Prepare Windows for Android development without installing Android Studio

Posted on 2021-08-16
●●●

Do you really need to install Android Studio to develop Android apps? No. However, most tutorials and docs say Android Studio is required. The truth is... Android Studio is advised to be installed only because it comes with all necessary tools to run and build android apps, it is essentially not needed as an editor.

This article aims at setting up a minimal Android environment sufficient to develop and build Android apps. For example, Flutter and React Native apps. For a fully-featured, rich Android development experience, it is better to install Android Studio.

If you do not want to install Android Studio and yet develop Flutter and React Native apps - this article is just for you. You are going to discover how to manually:

  • install Android SDK with build tools
  • use Android Studio Emulator to create and run Android Virtual Devices (AVDs)

Virtualization

Virtualization is a feature that allows to create virtual hardware. We will need to enable virtualization for Android Studio Emulator.

There are two ways to use virtualization: either through Hyper-V or HAXM. The setup depends on your PC. Read this small guide to see if virtualization is supported and how to enable it.

It is possible that your CPU is pretty old and does not support virtualization. Not that good, but do not worry. One option is to use very slow ARM-based Android Device images while keep using Android Studio Emulator. Another, more hardened solution is to just use third-party Android emulator such as Genymotion. This topic is touched one more time in the Android Studio Emulator section.

Java Development Kit (JDK)

Android SDK requires JDK to be installed. First, check if JDK is already installed. Open any terminal (CMD, Powershell, git-bash) and execute:

javac --version

If above command prints installed version, then JDK is already installed. Feel free to skip this section.

Installation:

  1. Download latest JDK version. Select JDK download > Windows x64 Compressed Archive

  2. Unpack downloaded .zip somewhere, e.g. C:\Program Files (x86)\Java\jdk-15.0.2 (version might be different for you)

  3. Add new system environment variable named JAVA_HOME, value must be the path to folder where you unpacked JDK in step 2. How to edit system environment variables

  4. To existing PATH system variable add:

    %JAVA_HOME%\bin
    

To verify installation, execute javac --version in terminal.

Android SDK

Android SDK is what allows to build and run Android apps. We gonna use sdkmanager CLI to download required SDK packages.

Installation:

  1. Download sdkmanager. Scroll to Command line tools only section, get .zip for Windows.

  2. Unpack downloaded .zip to C:\Android\cmdline-tools\latest so that bin folder is inside latest

  3. Add new system environment variable named ANDROID_HOME with value C:\Android. How to edit system environment variables

  4. To existing PATH system variable add:

    %ANDROID_HOME%\cmdline-tools\latest\bin
    %ANDROID_HOME%\emulator
    
  5. Open any terminal and execute:

    sdkmanager.bat --version
    

    If you did everything correctly, it should print the installed version.

  6. To see the list of all available packages that we can download:

    sdkmanager.bat --list
    
  7. We gonna install SDK packages of version 30. That version targets Android 11. From the terminal:

    sdkmanager.bat "platform-tools"
    sdkmanager.bat "build-tools;30.0.3"
    sdkmanager.bat "platforms;android-30"
    

    In case you need newer platform version, use the command from step 6 to check what packages are available for download. Installation pattern is the same as in above code snippet.

After installation, in folder C:\Android you should see a bunch of new folders and files.

Now all required tools are installed, including Android Studio Emulator. The only thing left is to download and configure an Android Virtual Device (AVD) itself.

Configuring and using Android Studio Emulator

Setting up an Android Virtual Device (AVD) is very similar to setting up a Virtual Machine (VM) using something like Virtual Box: get an image, then create virtual environment from the image.

NOTE: if virtualization is not enabled, your only option is to install ARM-based images which do not need hardware virtualization. When choosing an image, make sure it contains arm*, NOT x86/x64. ARM-based images are NOT recommended since they are slow and too often just broken (do not run). A better solution would be to use some other Android Emulator such as Genymotion

  1. List all system images available for download:

    // findstr works in CMD and Powershell
    // for unix-type shells use grep
    sdkmanager.bat --list | findstr system-images
    
  2. Download the image. We are going to use x86-based Android 11 image (API v30):

    sdkmanager.bat --install "system-images;android-30;google_apis;x86"
    
    // if virtualization is not enabled, use arm-type image
    sdkmanager.bat --install "system-images;android-30;google_apis;arm64-v8a"
    
  3. Create an AVD from the downloaded image using avdmanager:

    echo no | avdmanager.bat --verbose create avd --force --name "a11" --package "system-images;android-30;google_apis;x86" --tag "google_apis" --abi "x86"
    
    // for arm-type image
    echo no | avdmanager.bat --verbose create avd --force --name "a11_arm" --package "system-images;android-30;google_apis;arm64-v8a" --tag "google_apis" --abi "arm64-v8a"
    
    • --name for AVD alias. Pick something meaningful and short
    • --package must be image name from step 2
    • --tag image tag to use, taken from image name (google_apis)
    • --abi CPU architecture to use, taken from image name (x86 and arm64-v8a)
    • echo no to skip post-prompt

  4. List all installed AVDs:

    emulator -list-avds
    
  5. Launch AVD:

    emulator @a11
    

    Checkout all startup options over here. To stop emulator, just quit by pressing "X" or stop execution with "CTRL + C" in the terminal.

Congrats 🥳 You are now ready to go! All installed AVDs are located in User folder at ~/.android/avd. If you need to remove installed AVD, just delete folder with its name.

I recommend to use this gist as a cheatsheet for managing AVDs. That gist also gives a really awesome tip to make AVD more friendly. Open ~/.android/avd/an10.avd/config.ini and add those lines:

skin.name=1080x1920   # proper screen size for emulator
hw.lcd.density=480
hw.keyboard=yes       # enables keys from PC to be used in the emulator

Cheers! Go install React Native and start developing 💪

android

Written on 2021-08-16 by shelooks16