If ANDROID_HOME is not defined, the value in ANDROID_SDK_ROOT is used. If ANDROID_HOME is defined but does not exist or does not contain a valid SDK installation, the value in ANDROID_SDK_ROOT is used instead. Try echo $ANDROID_HOME . If that returns nothing try echo $ANDROID_SDK_ROOT .
Variable name: ANDROID_HOME , Variable value: the path where you installed the android SDK, in my case is, C:\Android\android-sdk . You have to add the variable to the Path variable system by adding this: ;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools; .
You may want to confirm that your development environment has been set correctly.
Quoting from spring.io:
Set up the Android development environment
Before you can build Android applications, you must install the Android SDK. Installing the Android SDK also installs the AVD Manager, a graphical user interface for creating and managing Android Virtual Devices (AVDs).
From the Android web site, download the correct version of the Android SDK for your operating system.
Unzip the archive to a location of your choosing. For example, on Linux or Mac, you can place it in the root of your user directory. See the Android Developers web site for additional installation details.
Configure the
ANDROID_HOME
environment variable based on the location of the Android SDK. Additionally, consider addingANDROID_HOME/tools
, andANDROID_HOME/platform-tools
to your PATH.Mac OS X
export ANDROID_HOME=/<installation location>/android-sdk-macosx export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Linux
export ANDROID_HOME=/<installation location>/android-sdk-linux export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Windows
set ANDROID_HOME=C:\<installation location>\android-sdk-windows set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
The Android SDK download does not include specific Android platforms. To run the code in this guide, you need to download and install the latest SDK platform. You do this by using the Android SDK and AVD Manager that you installed in the previous section.
Open the Android SDK Manager window:
android
Note: If this command does not open the Android SDK Manager, then your path is not configured correctly.
Select the Tools checkbox.
Select the checkbox for the latest Android SDK.
From the Extras folder, select the checkbox for the Android Support Library.
Click the Install packages... button to complete the download and installation.
Note: You may want to install all the available updates, but be aware it will take longer, as each API level is a large download.
In Linux
First of all set ANDROID_HOME in .bashrc file
Run command
sudo gedit ~/.bashrc
set andoid sdk path where you have installed
export ANDROID_HOME=/opt/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
to reload file run command
source ~/.bashrc
Now check installed platform, run command
ionic platform
Output
Installed platforms:
android 6.0.0
Available platforms:
amazon-fireos ~3.6.3 (deprecated)
blackberry10 ~3.8.0
browser ~4.1.0
firefoxos ~3.6.3
ubuntu ~4.3.4
webos ~3.7.0
if android already installed then need to remove and install again
ionic platform rm android
ionic platform add android
If not installed already please add android platform
ionic platform add android
Please make sure you have added android platform without sudo command
if you still getting error in adding android platfrom like following
Error: EACCES: permission denied, open '/home/ubuntu/.cordova/lib/npm_cache/cordova-android/6.0.0/package/package.json'
Please go to /home/ubuntu/ and remove .cordova folder from there
cd /home/ubuntu/
sudo rm -r .cordova
Now run following command again
ionic platform add android
after adding platform successfully you will be able to build andoid in ionic.
Thanks
These are the steps that you need to follow to successfully set up your Ionic Project to work with android emulator:
To add android platform:
First you need to setup the environment variables. For this you need to consider 3 files:
1. ~/.profile (For setting up the variables every time terminal opens or computer boots up):
//Code that you need to append at the last
set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export ANDROID_HOME='/home/<user_name>/Android/Sdk' <Path to android SDK>
export PATH=$PATH:$ANDROID_HOME/bin
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
2. /etc/environment (to set the environment variables):
//All the content of the file
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
ANDROID_HOME="/home/<user_name>/Android/Sdk" <Path to android SDK>
3. /etc/profile:
//Code that you need to add at the last
JAVA_HOME=/usr/lib/jvm/java-8-oracle <Path where Java is installed>
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
For loading the above changes made to the file you need to run the following command:
source ~/.profile
source /etc/environment
source /etc/profile
1. Add platform: ionic platform add android (Note that you need to run this command without sudo)
2. If you are still getting error in the above command then do the following: (here appName = helloWorld)
cd ..
sudo chmod -R 777 helloWorld
cd helloWorld
ionic platform add android
If you are still getting the error then remove ".cordova" folder from the home directory of your PC.
3. To run the app in your android emulator: ionic run android
Thanks!
For those having a portable SDK edition on windows, simply add the 2 following path to your system.
F:\ADT_SDK\sdk\platforms
F:\ADT_SDK\sdk\platform-tools
This worked for me.
I had this issue before.
You need to add sdks\tools
and sdks\build-tools
to your environment path.
April 11, 2019
None of the answers above solved my problem so I wanted to include a current solution (as of April 2019) for people using Ubuntu 18.04. This is how I solved the question above...
/usr/lib/Android/
Search for where the SDK is installed and the version. In my case it was here:
/usr/lib/Android/Sdk/build-tools/28.0.3
Note: that I am using version 28.0.3, your version may differ.
Add ANDROID_HOME
to the environment path. To do this, open /etc/environment with a text editor:
sudo nano /etc/environment
Add a line for ANDROID_HOME
for your specific version and path. In my case it was:
ANDROID_HOME="/usr/lib/Android/Sdk/build-tools/28.0.3"
Finally, source the updated environment with: source /etc/environment
Confirm this by trying: echo $ANDROID_HOME
in the terminal. You should get the path of your newly created variable.
One additionally note about sourcing, I did have to restart my computer for the VScode terminal to recognize my changes. After the restart, the environment was set and I haven't had any issues since.
Execute: sudo gedit ~/.bashrc
add
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH
export ANDROID_HOME=~/Android/Sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
and
source ~/.bashrc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With