“Cannot find a compatible Android SDK for compilation” on fresh installed Mac

Android SDK version

My old MacBook pro 13″ with only 8GB of RAM, did a good job for serving me well on mobile development journey. However, it could not keep up anymore with my current workload, I gave up long time ago of using emulator during development due to lack of memory and CPU power. Finally, I decided to switch to 2019 MacBook Pro 15″, this time I take 32GB one, better safe than sorry, hah.

In effort of getting more new Developer on board, NativeScript community recently update the official document and make so much better now. Especially the Environment setup guide. My team used to have a Wiki for new developers to get on board because the official docs had many flaws. Big thumb up for NativeScript team:

https://docs.nativescript.org/environment-setup.html#macos-android

However, I’m still facing a minor issue during attempt to setting Environment up on my fresh mac. Even after follow all detailed steps in official guide.

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

ns doctor keep yelling me at:

✖ 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. 

From the message I can clearly tell that something is wrong with my Android SDK, the build tools was old? Nope, I just installed Android Studio, and it come with Android SDK 31 as default recommended settings. But wait, first ns doctor said that Android SDK 28 or later”, but on the next line it mentioned that any version IN THE FOLLOWING RANGE: ‘>=23 <=30′”, this catches my attention.

Solutions for “Cannot find a compatible Android SDK for compilation.”

I could not found anywhere the official information about maximum supported build tools version except messages that “ns doctor” yelling about. Turned out that NativeScript do not support Android SDK and build tools version 31 (YET), which is installed by default on latest Android Studio version.

Be aware that SDK itself and build tools are different things. And can be installed separately.

The simplest way to get NativeScript back to work in this situation is open Android Studio and install older SDK version 30.

Make sure you selected:

  • SDK Platforms > Android 11.0 (R) API Level 30
  • SDK Tools > Android SDK Build-Tools 30

There is another trap when select Build-Tools version, don’t forget to click on “Show Package Details” at the bottom or you will not see the old versions.

Run ns doctor again, and now you are good to go:

In the conclusion, that ns doctor message was bit misleading. It should state that Android SDK 31 >= are not supported yet or something like they did with Build-Tools.

My ns version was 8.1.3 (latest at the time I wrote this post). Honestly I would not have a clue if there was no mentioned ‘>=23 <=30’ on Build-Tools version. Image if someone who have proper Build-Tools installed, but Android SDK 31 is installed they will be leave with this clueless message:

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

Hope community will fix the message, or maybe Android 31 will be supported soon 🤔.

===

Updated: this issue was fixed after I reported to NativeScript repos. Original issue link: https://github.com/NativeScript/nativescript-cli/issues/5589

This Post Has 3 Comments

  1. LovingEditing

    Great content! Keep up the good work!

  2. Simarjot

    Awesome! it’s really saved my life.

  3. Roshan

    Thanks. This was helpful

Leave a Reply