Cannot find a compatible Android SDK for compilation when running `tns platform add android`
Asked Answered
S

10

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!

Stace answered 22/9, 2015 at 17:59 Comment(1)
I am in the same situation. I'll update here once I fix this issue.Verbify
V
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.

Verbify answered 23/9, 2015 at 7:22 Comment(7)
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.Stace
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...Borneo
oops. i was missing the android_homeBorneo
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.Parlance
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.Hogweed
Well, this answer does not cover basic Android tutorial.Verbify
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.Blackball
B
8

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

Beitris answered 24/1, 2016 at 8:27 Comment(3)
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 you will be able to comment on any post. - From ReviewPairs
Although my English sucks, but it is the correct answer, I was through the actual testing.Beitris
running sudo echo $ANDROID_HOME still gives the location of my sdk. this doesn't solve the problemMatsuyama
P
7

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.

Pacific answered 3/8, 2016 at 14:8 Comment(0)
M
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

Morris answered 6/2, 2017 at 11:25 Comment(0)
T
1

I solve this problem installing Android Support Repository from Extras.

Truthvalue answered 7/9, 2016 at 9:19 Comment(0)
C
1

updating SDK in AndroidStudio >> Preferenceswould help

enter image description here

Chameleon answered 15/10, 2018 at 22:17 Comment(0)
B
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

Betoken answered 13/7, 2017 at 2:25 Comment(0)
F
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.

Fantan answered 2/9, 2021 at 5:40 Comment(0)
T
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

Thumbsdown answered 8/1, 2022 at 12:17 Comment(0)
A
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

Algology answered 22/1, 2023 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.