lazlojuly
lazlojuly

Reputation: 841

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

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!

Upvotes: 27

Views: 24484

Answers (10)

John Bhaktul
John Bhaktul

Reputation: 13

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

Upvotes: 0

yannick
yannick

Reputation: 649

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

Upvotes: 0

Brian
Brian

Reputation: 328

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.

Upvotes: 0

D C
D C

Reputation: 728

updating SDK in AndroidStudio >> Preferenceswould help

enter image description here

Upvotes: 1

Joshua Deshazer
Joshua Deshazer

Reputation: 193

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

Upvotes: 0

minato namikaze
minato namikaze

Reputation: 23

  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

Upvotes: 2

rjurado01
rjurado01

Reputation: 5535

I solve this problem installing Android Support Repository from Extras.

Upvotes: 1

Kumar Nitesh
Kumar Nitesh

Reputation: 1652

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.

Upvotes: 7

llj
llj

Reputation: 81

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

Upvotes: 8

Aniruddh
Aniruddh

Reputation: 7668

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.

Upvotes: 24

Related Questions