27

I am following an official NativeScript tutorial and having a problem configuring my OS X environment for android development.

When running tns platform add android I receive the following error:

Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 21 or later.

The tns doctor command also returns warnings on android-sdk issues:

Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 21 or later. Run $ android to manage your Android SDK versions. You need to have the Android SDK Build-tools installed on your system. You have to install version 22. Run "android" from your command-line to install required Android Build Tools. You need to have the latest Android Support Repository installed on your system. Run $ android to manage the Android Support Repository.

My android-sdk installation looks like this:

Android-SDK-installations

My .bash_profile also includes the followings:

export ANDROID_HOME="/usr/local/Cellar/android-sdk/24.3.4/"

export PATH="$PATH:~/npm-global/bin:/usr/local/Cellar/android-sdk/24.3.4/tools:/usr/local/Cellar/android-sdk/24.3.4/platform-tools"

Should I go further and try setting system-wide environment variables - not just for the .bash_profile? Also, it is possible that I missed something from the setup process...

Any tip on how I could debug this situation (commands, config files etc.) would be great, thank you!

lazlojuly
  • 829
  • 2
  • 8
  • 19

10 Answers10

24

Alright, so you need to make sure of following:

  • Make sure you have API 22 installed.
  • Make sure you you have Android SDK Build Tools 22.x.x installed. (Yes, specifically 22.x.x)
  • Make sure you have Android support repository installed. (You can find it under Extras section in Android SDK Manager)

Once you have performed steps mentioned above, run tns doctor again and you should see No issues were detected message.

Aniruddh
  • 7,648
  • 1
  • 26
  • 43
  • 3
    Thanks! Yes, the *tns* error message was confusing because it was saying: `To be able to build for Android, install Android SDK 21 or later` but then it also asks specifically for the `version 22 SDK` and this, I have ignored because I had a newer (v24) version already installed. Once I have installed SDK 22 and the Support Repository from the Extras, it works fine. – lazlojuly Sep 23 '15 at 09:12
  • 2
    I've followed these instructions and i keep getting the same message i have API 22 installed build-tools 22.0.1 installed and support repository 24 installed... – naoru Nov 09 '15 at 23:09
  • oops. i was missing the android_home – naoru Nov 09 '15 at 23:23
  • I had the same problem, but it was related to the "build-tools" not showing in the SDK Manager. I was following the tutorial instructions for NativeScript, specifically using chocolatey to get "android-sdk" was my issue. I decided to download the sdk via Android Studio and that solved the problem. – Richard Chassereau Jan 16 '16 at 03:22
  • HOW?! All of these answers only list other problems but not the actual steps to solve them. As someone with no familiarity with Android Studio I cannot find `Extras` in any of the menus, I can't find an Android SDK Manager application to run or a menu item to click. Running `$ android` returns `The "android" command is deprecated.` – Anthony Manning-Franklin May 10 '17 at 08:26
  • 1
    Well, this answer does not cover basic Android tutorial. – Aniruddh May 10 '17 at 22:04
  • Have in mind that this could happen with other versions, for example with "... build for Android, install Android SDK 27 or later." and you just need to install the next version, in the example the "28". Although it may be confusing by the "... or later", you need the next version. I don't really know why. – PhoneixS Oct 08 '21 at 10:09
8

This is because of sudo. The root user has no ANDROID_HOME set.

David Medenjak
  • 33,993
  • 14
  • 106
  • 134
llj
  • 81
  • 1
  • 2
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). - [From Review](/review/low-quality-posts/11007356) – Gabriele Mariotti Jan 24 '16 at 09:11
  • 1
    Although my English sucks, but it is the correct answer, I was through the actual testing. – llj Jan 24 '16 at 09:40
  • running sudo echo $ANDROID_HOME still gives the location of my sdk. this doesn't solve the problem – Phil Jul 01 '16 at 16:55
8

For Windows User:

  1. Run 'android update sdk' from command line
  2. Select Android 5.1.1(API22)
  3. Select Tools folder
  4. Select Extras and click on Install.

ps:- adding this answer, so that if any one land on this page can see it.

Kumar Nitesh
  • 1,634
  • 15
  • 18
2
  1. Check the ANDROID_HOME is ok
  2. Install the API 22 + ion the Extras > Android Support Repository
  3. Run the following

    • tns platform remove android
    • tns platform add android@next
  4. Run

    tns run android

then it should be OK

1

I solve this problem installing Android Support Repository from Extras.

rjurado01
  • 5,337
  • 3
  • 36
  • 45
1

updating SDK in AndroidStudio >> Preferenceswould help

enter image description here

D C
  • 708
  • 1
  • 6
  • 17
0

on my windows 10 machine I had to open file explorer right click on this pc and go to properties on the left hand side I had to go to advanced settings. At the bottom I click environment variables then on the android_home variable I clicked edit then pointed it to this path on my machine where the sdk was installed C:\Program Files (x86)\Android\android-sdk

Joshua Deshazer
  • 171
  • 3
  • 15
0

This answer is on a Linux, not OSX, platform. However, since this is the SO that appears most often for the listed error, I'll share a recent fix that worked for me.

If you have done all of the above and are still getting the error, try this solution.

I am using NativeScript 8.0.2.

You will know that ANDROID_HOME and Java are configured correctly if you can run the command $ANDROID_HOME/tools/bin/sdkmanager --list. If that fails, then first check that your Java is compatible (I had to add OpenJDK 8 and change my PATH with export JAVA_HOME="/usr/lib64/jvm/java-1.8.0/")

In Android Studio, add a previous build tool version. Go to your SDK Manager > SDK Tools, tick the bottom box "Show package details", and add a previous version. In my case, 31.0.0 was the latest, and I added 30.0.3. Now run ns doctor android again and everything should pass.

Seems 31.0.0 is not yet properly recognised by Native Script.

Brian
  • 198
  • 1
  • 1
  • 8
0

I always got the error "✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later. "

I actually had to go to the android studio settings and install the exact SDK 28 before this error went away. Android Settings Pic

yannick
  • 579
  • 3
  • 4
0

This is an updated answer, I also had the same issue:

ns doctor android in Terminal on Windows 11

Like all the previous pictures above, I had to install the SDK platforms, using the SDK Manager. From the main screen of Android Studio, click More Actions and choose SDK Manager. Before that I had to add the platform-tools to my PATH in Windows

%LOCALAPPDATA%\Android\Sdk\platform-tools

That fixed my issue and the docs for setup are here.

enter image description here