Search code examples
androidnativescriptangular2-nativescript

Nativescript CLI says Android SDK not configured properly, but I don't know how to fix it


I am developing a Nativescript app and would like to run it on my physical Android device (Huawei P10 lite) via USB.

I downloaded the Android SDK CLI tools and extracted it into my ~/Android/ directory and I've set my environment variable ANDROID_HOME to /home/<username>/Android. When I run tns run android I expect the app to launch on my phone, however it prints out:

✔ Your ANDROID_HOME environment variable is set and points to correct directory.
✔ Your adb from the Android SDK is correctly installed.
✔ A compatible Android SDK for compilation is found.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Local builds for iOS can be executed only on a macOS system. To build for iOS on a different  operating system, you can use the NativeScript cloud infrastructure.
✖ 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

Your environment is not configured properly and you will not be able to execute local builds.

There is no indication of what exactly isn't configured properly. So I don't know what I should try next?

I'm running on Ubuntu 18.04.5. My ~/Android/ directory looks like

-rwxr--r-- android
drwxr-xr-x bin/
drwxr-xr-x build-tools/
-rwxr--r-- emulator
-rwxr--r-- emulator-check
-rw-r--r-- .knownPackages
drwxr-xr-x lib/
drwxr-xr-x licenses/
-rwxr--r-- mksdcard
-rwxr--r-- monitor
-rw-r--r-- NOTICE.txt
drwxr-xr-x platforms/
drwxr-xr-x platform-tools/
drwxr-xr-x proguard/
-rw-r--r-- source.properties
drwxr-xr-x support/

I've set up symlinks for adb -> /home/<username>/Android/platform-tools/adb and emulator -> /home/<username>/Android/platform-tools/emulator and placed the links inside the ~/.bin/ directory. This directory is checked when searching for terminal commands and I can successfully run them from any directory this way.


Solution

  • After some digging around, I figured out the problem. The downloaded Android CLI tools was extracted in my top level ~/Android/ directory. The CLI tools should actually be put in the ~/Android/tools/ directory. After I made this change, tns doctor found no issues and I could run tns run android successfully.

    My ~/Android/ directory structure looks like this now:

    build-tools/
    .knownPackages
    licenses/
    platforms/
    platform-tools/
    tools/
    

    The ~/Android/tools/ directory looks like this now:

    android
    bin/
    emulator
    emulator-check
    lib/
    mksdcard
    monitor
    NOTICE.txt
    proguard/
    source.properties
    support/
    

    Part of the android setup that I missed It says

    The archive you just extracted was the tools folder, so in this case it would be at: /usr/local/android/sdk/tools

    Where /usr/local/android/sdk is ~/Android in my case.