Home > Net >  Getting "ANDROID_HOME environment variable is not set" when running "ns run" & &
Getting "ANDROID_HOME environment variable is not set" when running "ns run" & &

Time:09-29

I'm using MacOS. I've already used Android Studio and Xcode to one of my react-native projects before. I am now learning SvelteNative. As I've started following the docs here and here, and got onto the step where I need to run ns doctor android I get this error:

zeddrix@Zeddrixs-MacBook-Pro todoapp % ns doctor android
✔ Getting environment information 

TIP: To avoid setting up the necessary environment variables, you can use the Homebrew package manager to install the Android SDK and its dependencies.

There seem to be issues with your configuration.
✔ Getting NativeScript components versions information...
✔ Component nativescript has 8.1.2 version and is up to date.
⚠ Update available for component @nativescript/core. Your current version is 7.0.0 and the latest available version is 8.1.3.
⚠ Update available for component @nativescript/android. Your current version is 7.0.0 and the latest available version is 8.1.1.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Xcode is installed and is configured properly.
✔ xcodeproj is installed and is configured properly.
✔ CocoaPods are installed.
✔ CocoaPods update is not required.
✔ CocoaPods are configured properly.
✔ Your current CocoaPods version is newer than 1.0.0.
✔ Python installed and configured correctly.
✔ The Python 'six' package is found.
✔ Xcode version 13.0.0 satisfies minimum required version 10.
✖ 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. 
 To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory. 

✖ WARNING: adb from the Android SDK is not installed or is not configured properly.  
 For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ WARNING: The Android SDK is not installed or is not configured properly. 
 You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK 
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later. 
 Run `$ sdkmanager` to manage your Android SDK versions. 

✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'. 
 Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly. 

Cannot read property 'toLowerCase' of null
zeddrix@Zeddrixs-MacBook-Pro todoapp % 

I get this too when running ns run:

zeddrix@Zeddrixs-MacBook-Pro todoapp % ns run
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✖ 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. 
 To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory. 

✖ WARNING: adb from the Android SDK is not installed or is not configured properly.  
 For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ WARNING: The Android SDK is not installed or is not configured properly. 
 You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK 
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later. 
 Run `$ sdkmanager` to manage your Android SDK versions. 

✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'. 
 Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly. 

Your environment is not configured properly and you will not be able to execute local builds.
Verify that your environment is configured according to the system requirements described at
https://docs.nativescript.org/environment-setup.html#macos-android.
zeddrix@Zeddrixs-MacBook-Pro todoapp % 

I tried uninstalling Android studio and then installing it again because I was thinking it could be the cause but still nothing. I didn't do this with Xcode because it takes very long to get it downloaded and since this error about ANDROID doesn't seem to have a connection about Xcode.

Then I searched for solving the issue about the missing or misplaced ANDROID_HOME environment variable. This article helped me.

So I ran:

cd ~/

touch .bash_profile

open -e .bash_profile

And then put these in .bash_profile:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools

But still got nothing... I don't know how to solve the next warnings below this, too. Help.

CodePudding user response:

After days of waiting and researching, I've read the official Android Studio docs for setting env vars. And saw that:

(ANDROID_SDK_ROOT) 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. ANDROID_HOME, which also points to the SDK installation directory, is deprecated. If you continue to use it, the following rules apply: If ANDROID_HOME is defined and contains a valid SDK installation, its value is used instead of the value in ANDROID_SDK_ROOT. 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.

I know that I can do this for ANDROID_HOME. But since the docs says here that it's deprecated, I've decided to do this on the ANDROID_SDK_ROOT instead. I opened up my Terminal and ran this:

set ANDROID_SDK_ROOT=Users\zeddrix\Library\Android\sdk\

It seemed like the CLI is waiting for another command after I did this so I then did this:

export ANDROID_SDK_ROOT=/Users/zeddrix/Library/Android/sdk

The error about this ANDROID_HOME has gone. Now I only had one error left to solve:

You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'. 
 Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.

The first comment in this question helped me through. I went to SDK Manager of my Android Studio > SDK Tools and then as @Kevin McCarpenter said:

"Uncheck (check actually) 'Show Package Details' and then you can select a lower version. If you're not building for android 12 (and you probably aren't yet), you can uncheck '31.0.0' and check '30.0.3'. After that, go into the build.gradle in your app and change buildToolsVersion '31.0.0' to buildToolsVersion '30.0.3'"

Then I ran ns run android (as said when I run ns run --help) and it finally worked!

  • Related