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!