Horje
How to set ANDROID_HOME path in Ubuntu?

ANDROID_HOME is an environment variable that tells our system that where the Android SDK (Software Development Kit) is located. And it is a set of tools. It sets the path to the SDK installation directory. Once set, the value does not typically change and can be shared by multiple users on the same machine, it also sets the path to the user preferences directory for tools that are part of the Android SDK and defaults to $HOME/.android/ .

How-to-set-ANDROID_HOME-path-in-ubuntu-copy

ANDROID_HOME PATH

Importance of setting ANDROID_HOME

Setting the ANDROID_HOME environment variable ensures that tools such as Gradle, Flutter, and other build systems can find and use the Android SDK.

Prerequisites

Before setting up ANDROID_HOME, make sure you have these files in your laptop or pc:

Verifying Java installation

To check if Java is installed, run:

java -version

If Java is not installed, follow the instructions on installation of JDK to install it. Then again run the command on cmd.

Downloading Android SDK

1. Obtaining the SDK

Download the Android SDK command-line tools.

2. Extracting the SDK archive

Once downloaded, extract the archive to your preferred location.

For example:

mkdir -p ~/Android/Sdk
unzip commandlinetools-linux-*.zip -d ~/Android/Sdk

Setting Up ANDROID_HOME Environment Variable

1. Locating the SDK path

The SDK path is the directory where you extracted the SDK tools.

For example: ‘ ~/Android/Sdk ‘ .

2. Adding ANDROID_HOME to ‘ .bashrc ‘ or ‘ .zshrc ‘

Open your ‘.bashrc‘ (or ‘.zshrc‘ if you use Zsh) file in a text editor:

nano ~/.bashrc

OR

nano ~/.zshrc

Add the following lines at the end of the file:

export ANDROID_HOME=~/Android/Sdk

Save and close the file.

3. Adding platform-tools to PATH

This ensures that the platform-tools directory, which contains Android Debugger Bridge( ‘adb’ ) and other essential tools, is included in your system’s ‘PATH’.

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Verifying the Configuration

1. Reloading the terminal

To apply the changes, reload your terminal or source the ‘.bashrc’ file:

source ~/.bashrc

OR

source ~/.zshrc

2. Checking ANDROID_HOME

Verify that the `ANDROID_HOME` variable is set correctly, run the command:

echo $ANDROID_HOME

You should see the path to your Android SDK.

3. Confirming SDK tools accessibility

Check if the SDK tools are accessible by running:

adb --version

This should display the version of the ‘adb’ tool, confirming the setup is correct.

Conclusion

Setting up the `ANDROID_HOME` variable that involves downloading of the SDK, configuring environment variables, and verifying the setup. This ensures a smooth development environment for Android applications.

How to set ANDROID_HOME path in Ubuntu – FAQs

What should I do if ‘ adb ’ is not recognized as a command after setting ANDROID_HOME?

Ensure ‘ platform-tools ’ is added to ‘ PATH ’ in your ‘ .bashrc ’ or ‘ .zshrc ’:

export ANDROID_HOME=~/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Reload the terminal with:

source ~/.bashrc

Verify ‘ platform-tools ’ exists:

ls ~/Android/Sdk/platform-tools

Install missing tools using:

sdkmanager "platform-tools"

How do I update the Android SDK after setting ANDROID_HOME?

Navigate to ‘ tools/bin ‘ in the SDK path:

cd ~/Android/Sdk/tools/bin

List and update packages:

./sdkmanager --list
./sdkmanager --update

Update specific components:

./sdkmanager "platforms;android-30" "build-tools;30.0.3"

Why is my ‘ ANDROID_HOME ’ variable not persistent across terminal sessions?

Ensure ‘ ANDROID_HOME ‘ is added to ‘ .bashrc ’ or ‘ .zshrc ’:

export ANDROID_HOME=~/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Apply changes with:

source ~/.bashrc

Check the variable with:

echo $ANDROID_HOME



Reffered: https://www.geeksforgeeks.org


TechTips

Related
How to Enable/Disable Sticky Scroll in VS Code? How to Enable/Disable Sticky Scroll in VS Code?
How to Fix WiFi issue in Ubuntu? How to Fix WiFi issue in Ubuntu?
10 Ways to Track and Recover Your Lost/Stolen iPhone 10 Ways to Track and Recover Your Lost/Stolen iPhone
How to Fix Calculator App Not Working on iPhone? How to Fix Calculator App Not Working on iPhone?
How to Check Ubuntu Crash Log in the Last Session? How to Check Ubuntu Crash Log in the Last Session?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
20