Nalin Adhikari
Nalin Adhikari

Reputation: 606

The ANDROID_HOME environment variable is not set or it points to a non-existent directory in Ubuntu

I placed Android SDK inside /opt/android-sdk and also updated .bashrc file with the lines :

export ANDROID_HOME="/opt/android-sdk" export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH

then I reloaded the .bashrc file:

source ~/.bashrc

After that I checked the ANDROID_HOME by hitting the command as:

echo $ANDROID_HOME

which resulted as:

/opt/android-sdk

which is the correct location where I placed it. After that I created a NativeScript Mobile Application project :

tns create MobileApp --ng

then I entered inside the MobileApp directory and tried to add platform as Android:

tns platform add android

but I got this error which stated as follow :

The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.

Did I miss anything in the above process of adding Android as platform in NativeScript Mobile Application project?

Upvotes: 5

Views: 14007

Answers (2)

Praveen Kumar
Praveen Kumar

Reputation: 91

There is a perfect solution here, you may face other problems too. I've provided the solutions for other as well.

setting up the NS (native script). tns doctor android home issue.unable to run this command.

  • Changed the environment variable to

  • set ANDROID_HOME=C:\ installation location \android-sdk

  • set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

  • Close cmd or VS, and restarted it, ran it again

  • Done.

Unable to craete the basic project from tns create. (there was an issue with JSON string)

  • Delete all the files from this location.

  • C:\Users\binu\AppData\Roaming\npm and

  • C:\Users\binu\AppData\Roaming\npm-cache

  • Then update your npm to the latest version by running npm i npm@latest -g npm i -g nativescript

  • [Done]

Need to create android emulator to run the test, one of the method is avd manager.

  • cd $ANDROID_HOME/tools/bin

  • sdkmanager "system-images;android-25;google_apis;x86"

  • avdmanager create avd -n test -k "system-images;android-25;google_apis;x86"

  • and then run "tns run android"

  • but now if it shows black screen.

  • sdkmanager emulator

  • [done]

Upvotes: 1

Nalin Adhikari
Nalin Adhikari

Reputation: 606

Issue solved :

I added ANDROID_HOME and PATH in .profile file in $HOME directory as :

export ANDROID_HOME="/opt/android-sdk" export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

then I restarted the system and tried with below command :

tns platform add android

and then it worked. Here's the logs for reference.

Copying template files...
◠ Installing [email protected] node_modules/babel-traverse
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected])
◝ Installing [email protected] node_modules/babel-types
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] ([email protected], [email protected])
◝ Installing [email protected] node_modules/babylon
◝ Installing [email protected] node_modules/lazy
Project successfully created.

Upvotes: 10

Related Questions