241

After updating to Android Gradle plugin 3.6.0 (released Feb 24, 2020), several project independently started failing with:

No version of NDK matched the requested version 20.0.5594570. Versions available locally: 21.0.6113669

It's quite simple to "fix" this locally by installing the older expected ndk version:

sdkmanager 'ndk;20.0.5594570'

However, my question is: Where and how is this older version specified? And how do I update it so it matches the latest version 21.0.6113669?

spydon
  • 9,372
  • 6
  • 33
  • 63
friederbluemle
  • 33,549
  • 14
  • 108
  • 109
  • 36
    AND build fails on Github CI, too. – KYHSGeekCode Feb 26 '20 at 11:17
  • same for me. And if I install that ndk, or specify its location, i get my app crashed because of UnsatisfiedLinkError -_- – ildar ishalin Feb 29 '20 at 10:36
  • 1
    Currently github ci now works again for my project: https://github.com/KYHSGeekCode/Android-Disassembler/blob/b6c9328bf5db1aa179ed24b15458edc96bdf4a4d/app/build.gradle#L73 – KYHSGeekCode Mar 02 '20 at 04:13
  • AND it fails in Circle CI, too. – HX_unbanned Mar 22 '20 at 23:01
  • this is the same as: https://stackoverflow.com/questions/61157024/compatible-side-by-side-ndk-version-was-not-found-default-is-20-0-5594570/61510602#61510602 – Gerry Apr 29 '20 at 20:08
  • Refer to [the fix](https://stackoverflow.com/questions/61157024/compatible-side-by-side-ndk-version-was-not-found-default-is-20-0-5594570/61510602#61510602) for more details/background. – Gerry Apr 29 '20 at 20:12

25 Answers25

170

The following solutions assume that the machine you are using currently has NDK installed and was previously able to build your project but started failing with the error "No version of NDK matched the requested version" after updating to Android Gradle plugin 3.6.0. Before proceeding make sure to have NDK installed.

Option 1:

You can simply select your locally installed NDK in the Project Structure Dialog

You can open the Project Structure Dialog by clicking File > Project Structure... or by pressing the hotkeys CTRL + ALT + SHIFT + S (on windows)

Once the Project Structure Dialog is open, go to SDK Location and select your locally installed version of NDK under Android NDK Location. Typically this is installed somewhere in your user folder then \AppData\Local\Android\Sdk\ndk\%ndk version% at least for Windows.

Project Structure dialog screenshot - from Android Studio 3.6 Build #AI-192.7142.36.36.6200805, built on February 12, 2020

Option 2:

Doing option 1 will edit your local.properties file for you and will work in most cases. But if you want to use a consistent NDK version on all machines you build the project with, according to this official guide, you can configure it from your module gradle script. Simply add the ndkVersion in your module gradle script's android{} block like so.

android {
    ndkVersion "major.minor.build"
}

replacing the string between the doublequotes with the NDK version you want to use

Option 3:

If you want all projects built on a particular machine to use the same NDK version, you can also set ANDROID_NDK_HOME environment variable with the path to the NDK folder.

Rutvik Bhatt
  • 3,185
  • 1
  • 16
  • 28
Subaru Tashiro
  • 2,166
  • 1
  • 14
  • 29
  • 1
    What if I want to use the latest ndkVersion using Option 2? – KYHSGeekCode Feb 27 '20 at 01:47
  • @KYHSGeekCode you can replace the string between the doublequotes with the NDK version you want to use. Make sure you have that particular version installed. – Subaru Tashiro Feb 27 '20 at 05:47
  • 8
    I mean, can I use the latest version(not specifying manually)?, using something like `$NDK_LATEST_VERSION` – KYHSGeekCode Feb 29 '20 at 00:07
  • 3
    That's never been an option for any way of specifying the NDK. Doing that would make your build non-reproducible, which leads to all kinds of debugging headaches. Probably what you'd want is to rely on the default version used by the gradle plugin (which may not be the latest, but should be sufficiently new as long as your plugin is up to date). Right now that's a pain because the default version won't be auto downloaded, but that's fixed in 4.1. – Dan Albert May 04 '20 at 23:30
  • 1
    Another thing that would keep builds reproducible while also making it easy to stay up to date would be to have a notification whenever the explicitly set `android.ndkVersion` is something other than the latest NDK. Having an actual "latest" value has some questions with non-obvious answers. Should latest point to the latest stable release, or just the newest thing available? Latest thing on the disk, or latest available from the SDK? How often should the build check? How do you make sure old revisions of your project remain buildable? – Dan Albert May 04 '20 at 23:34
  • My ndk folder was empty, had to install 'NDK (Side by Side)' in 'SDK Tools' in SDK manager to get something in it. Added the path starting with the '...' button, although you have to unhide the AppData folder (initially greyed out) to get access to its contents. – Androidcoder Jun 10 '20 at 17:09
110

I have the same issue. I resolved it through the SDK manager under SDK Tools, click Show Package Details and then scroll under NDK (Side by side) and tick and apply the version you need. See image below:

Image link to SDK tools for NDK version install

My question for anyone is, why do we need this now for projects that do not require the NDK? As it turns out the NDK is a pre-existing requirement in the project I work on for a dependency!

kelvin
  • 1,269
  • 1
  • 8
  • 8
  • 10
    I found this setting on mac in Android Studio by going Preferences -> Appearance & Behaviour -> System Settings -> Android SDK and clicking SDK Tools like screenshot And also check "Show Package Details" – Dylan w Dec 21 '20 at 08:19
  • 4
    This is absolutely perfect answer. Thanks for saving our time. – Kamal Kant Mar 02 '21 at 14:35
81

It isn't necessary with Android gradle plugin > 4.1.0 (please see also https://issuetracker.google.com/issues/144111441)

With < 4.1.0 I run into this too

No version of NDK matched the requested version 20.0.5594570. Versions available locally: 21.0.6113669

Option 1:

You can simply select your locally installed NDK in the Project Structure Dialog works ! enter image description here

But is only valid for local builds, an I need a solution for CI

Option 2:

It's only works, when you specify it in every used module

android {
    compileSdkVersion 28
    ndkVersion "21.0.6113669"
    ...
}

Here it seems not to work https://github.com/hannesa2/panoramagl/pull/17/checks with this change https://github.com/hannesa2/panoramagl/pull/17/files#diff-cff4e8c294a5dc5e76308662ae1ddcacR6-R7

Option 3:

export ANDROID_NDK_HOME=/Users/{my-user}/Development/adt/sdk/ndk/21.0.6113669

works too as well !

hannes ach
  • 16,247
  • 7
  • 61
  • 84
  • what do you mean by Option 2 not working at all? What problem are you encountering with that approach? Have you taken a look at the bottom of this page? https://developer.android.com/studio/projects/install-ndk#apply-specific-version – Subaru Tashiro Mar 02 '20 at 18:52
  • @SubaruTashiro Look, it seems not to work https://github.com/marianmoldovan/panoramagl/pull/17/checks?check_run_id=479002568 with this change https://github.com/marianmoldovan/panoramagl/pull/17/files#diff-cff4e8c294a5dc5e76308662ae1ddcacR6-R7 or I don't know why – hannes ach Mar 02 '20 at 20:27
  • Strange. I can see in your commits that you specified `21.0.6113669` but the build logs says the requested version is `20.0.5594570`. Can you look for a `ndk_locator_record.json` file? That file has information on how it resolved the requested ndk version. – Subaru Tashiro Mar 03 '20 at 06:54
  • @SubaruTashiro I search for it, and there is no such file. Look I search for it in step " Search for ndk_locator_record.json before" https://github.com/hannesa2/panoramagl/pull/17/checks?check_run_id=484224272 – hannes ach Mar 04 '20 at 06:53
  • 2
    Seems like option 3 is deprecated: `WARNING: Support for ANDROID_NDK_HOME is deprecated and will be removed in the future. Use android.ndkVersion in build.gradle instead.` – azizbekian Aug 17 '20 at 09:09
  • Option 2 worked for me. Had to set ndkVersion in every module of my project. – TGruenwald Aug 29 '20 at 19:30
  • setting in every module is wrong, it should only be needed in the modules that actually do build native files! – eri0o Jan 27 '21 at 01:59
  • Support for ANDROID_NDK_HOME and ANDROID_NDK_ROOT has ended; Option 3 no longer works. – Joe Bowbeer Apr 10 '21 at 18:30
24

To answer the part of your question not answered by others, "Where and how is this older version specified? And how do I update it so it matches the latest version 21.0.6113669?":

The default version is set by the Android Gradle plugin. Each version will default to whatever version of the NDK that we used during testing to guarantee the best possible compatibility.

The difference between this and earlier plugin versions is that it used to happily use any NDK that you happened to have installed. This caused a ton of "works on my machine" issues for users where their co-workers couldn't build the project, it wouldn't work on CI but would locally, etc. It wasn't a good situation.

You can pick a specific version of the NDK to use in your project by setting android.ndkVersion in your build.gradle. if you don't, it'll try to use the default version for the Gradle plugin that you're using.

The annoying bit is that most versions (until 4.1) will not automatically download the default version, which gives you the error you're seeing. If you explicitly pick a version in your build.gradle it actually will download automatically, and with 4.1 it will automatically download the default version too.

A thing that often confuses people is why this hits them when they're not using the NDK, or at least believe they are not. The answer in that case is that one of your dependencies includes native libraries and these need to be stripped before they are packed into the APK to keep size down, and strip comes from the NDK.

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
  • "before they are packed into the NDK" - Do you mean "packed into the APK"? – Hannes Struß Jul 20 '20 at 12:53
  • Thank you for providing the answer to the key part of the original question. – Hong Jul 22 '20 at 15:03
  • hmm.. Isn't it possible to make strip part of the standard SDK? It is annoying to have to download several GBs for installing an NDK that I don't really need, just to get a strip command. Or may be there is more to the problem than just strip command. – rineez Aug 09 '20 at 16:47
  • If a fallback was added to use strip from build-tools when the NDK isn't installed that would be another way to introduce "works on my machine", since different users might get different sets of tools for the same project depending on what they have installed. We don't want to _always_ use the strip from build-tools because that can cause other issues if your compiler and strip don't match (ELF is still evolving, so strip does actually need to be up to date). The current solution might not be the best approach. Feel free to file a Studio bug if you want to open that discussion. – Dan Albert Aug 12 '20 at 23:51
  • We do want to reduce the size of the NDK (and the size of downloads in general) though, and have some avenues to do so for Linux and Darwin, so maybe that's enough to settle your concerns :) – Dan Albert Aug 12 '20 at 23:52
19

This worked for MacOS, check via Terminal:

cd ~/Library/Android/sdk
ls

If you see "ndk" and/or "ndk-bundle", delete them:

sudo rm -r ndk/
sudo rm -r ndk-bundle/

After deleting those folders, everything worked for me. This is copied from GitHub

Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58
13

In the last version of Gradle there is no need to define the NDK versión inside the build.grade :

android {
    ...
    ndkVersion "21.0.6352462"
    ...
}

We must install the suggested versión

enter image description here

or define the current available version into the Android NDK Location:

enter image description here

enter image description here

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
13

replace gradle classpath with this in Project level build.gradle

   classpath 'com.android.tools.build:gradle:4.1.0'

in gradle-wrapper.properties add this line

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Aviraj Patel
  • 270
  • 4
  • 16
  • This is the best answer, they admitted that the loss of automatic fetching of the NDK if a specific version was required was a "bug", and 4.1.0 or higher of the plugin fixes that. – dragon788 Dec 23 '21 at 18:21
  • That was a mind-numbingly simple answer that fixed my mysterious error. The continued mystery is why none of my colleagues working on the same project had this issue. No idea. But, one mystery at a time... – Mike S. Jul 01 '22 at 16:46
9

I faced the same problem. Then i found the developer references here

Default NDK version per AGP version

So, the problem start with gradle version 3.6. Before 3.6 there was no default ndk specified. So, any version of ndk worked without any problem. But after adding default version, if we not add any ndkVersion in build.gradle then it search for the default version of ndk.

In my case, my gradle version was 3.6.3 and ndk installed 21.0.6113669 and i did not defined ndkVersion in my build.gradle. So, it search for default ndkVersion "20.0.5594570" according to my gradle version and gave me the same error. So, i simply add ndkVersion "21.0.6113669" in my build.gradle file and error gone.

Amanullah Asraf
  • 376
  • 4
  • 9
8

In order to solve this problem, you must indicate to your IDE the version of your NDK in build.gradle. In this case, it should be version 21.0.6113669. For example:

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.remed_mobile"
    minSdkVersion 16
    targetSdkVersion 28
    ndkVersion '21.1.6352462'
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

If you do not indicate your version number, then the IDE takes a default version. If you've upgraded gradle, then it might not find the right version.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
7

Add this line in build.gradle(app)

android {

ndkVersion "21.0.6113669"

}

This will solve the problem

https://github.com/gradle/gradle/issues/12440#issuecomment-606188282

saif uddin
  • 71
  • 1
  • 1
6

This workes for me

edit local.properties file to add this

ndk.dir=/xxxxx/Android/sdk/ndk-bundle
ohdroid
  • 771
  • 6
  • 3
5
Android Studio -> Preferences -> System settings -> Android SDK -> Got to SDK tools  and remove NDK(Side by Side) and apply.

 ndkVersion "21.0.6113669" ///  <<---Add this in your android -> app -> build.gradle file.

  buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
    ndkVersion "21.0.6113669" 
Sriraksha
  • 459
  • 1
  • 8
  • 15
4

i had same problem, after a while i found a temporary solution. rename ndk folder to ndk-bundle. in your projects go to local.properties file and add this line before sdk.dir:

ndk.dir=<path to your ndk folder>

its mine:

ndk.dir=G\:\\SDK\\ndk-bundle
sdk.dir=G\:\\SDK

i hope it help you

kam.r
  • 61
  • 6
  • Nice. This works. Do you know any way that the build system could generate this line automatically as it already can for the sdk.dir option ? – Nicolas Dusart Mar 23 '20 at 10:15
  • you can also specify path to the ndk folder, instead of renaming. the string `ndk.dir=G\:\\...\\Sdk\\ndk\\21.0.6113669` worked for me. – Artem Mostyaev Apr 17 '20 at 15:07
4

I also got below error

No version of NDK matched the requested version 20.0.5594570. Versions available locally: 21.3.6113669

I just added my local NDK version to App level build.gradle file its solved.

    android {
        ndkVersion "My Available version here"  (my case it 21.3.6113669)
    }

flutter clean 
flutter pub get
Dharman
  • 30,962
  • 25
  • 85
  • 135
imssurya
  • 439
  • 4
  • 8
3

After upgrading to gradle:3.6.0 (or later). Try renaming or deleting the ndk and ndk-bundle folders located in C:\Users\<user>\AppData\Local\Android\Sdk

Credit goes to: https://github.com/gradle/gradle/issues/12440#issuecomment-601214647

Ian M
  • 355
  • 3
  • 9
2

Change your classpath version to 3.5.0 inside your build.gradle, project level.

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
}

I have the same issue and it solved.

djalmafreestyler
  • 1,703
  • 5
  • 21
  • 42
  • 5
    Well, it's not really a solution, but a workaround at best. I already mentioned that the error started happening when _updating_ to `3.6.0` (or later). Btw, you don't need to downgrade to `3.5.0`. Version `3.5.3` works fine as well. – friederbluemle Mar 09 '20 at 17:51
2

No version of NDK matched the requested version 20.0.5594570

Here I got solution

1====>first download NDK if you don't haveClick on download

2====>Rename your NDK as your Project need (like here I need 20.0.5594570)

3====>After that in android folder open gradle.properties file

here you put your ndk location like this

then do react-native run-android... that's it

NDK issues resolved

thanks you!

Manoj Kashyam
  • 168
  • 4
  • 23
2

go to your app's build.gradle file;

in android{ } add your ndk version available, this shows in your error info you post. In this case, your version is "21.0.6113669"

No version of NDK matched the requested version 20.0.5594570. Versions available locally: 21.0.6113669

android { ndkVersion "21.0.6113669" }

Michael Yang
  • 1,403
  • 2
  • 18
  • 27
1

Open your module's build.gradle file and edit :

android {
        **ndkVersion** "version number of you NDK"
    }
Suyash
  • 190
  • 1
  • 10
1

If you have trouble finding an exact version of NDK you can download it from here, it was the case for me my IDE required version 21.1.6352462 while this version no longer exists on the official site (https://developer.android.com/ndk/downloads)

All Android NDK Native Development Kit by API,Version and OSes

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30381016) – nighthawk Nov 20 '21 at 21:16
  • Thanks, Old version NDK download link is very help full to me. I have download old version and setup project. – Vishal Gadhiya Sep 07 '22 at 09:45
1

I found this problem in as fox or 4 In X. In the root directory of OS, open and hide Gradle folder

add file gradle.properties
add code 
ndk.dir=/Users/your os name/Library/Android/sdk/ndk

doen~

dee13600
  • 11
  • 2
1

first install NDk from android studio and Tools>sdk manager>sdk tools than download ndk version and enter image description here

than in your local.properties set ndk path like this:

ndk.dir=/Users/{yourUserName}/Library/Android/sdk/ndk/21.4.7075529

Rajan rek
  • 322
  • 2
  • 8
1

If you're using frameworks then

  1. Go to build.gradle in android => app folder and add

    android { ndkVersion rootProject.ext.ndkVersion }
    
  2. Gotp build.gradle in android folder and add

    buildscript {
        ext {
           ndkVersion = "23.1.7779620"
        }
    }
    
  3. Clean the gradle and run the project again.

António Ribeiro
  • 4,129
  • 5
  • 32
  • 49
0

I couldn't install the specified version (a weird error from android studio, it might be related to the Silicon chip), so I specified a newer version of ndk in my build.gradle and everything worked.

Alberto M
  • 1,608
  • 1
  • 18
  • 42
0

[My Error: requested ndk version 22.0.7026061 did not match the version 20.0.5594570 requested by ndk.dir]

MySolution: There seems to be different ndk versions pointing out in different places

Please find below details for the same: Please go to

  1. Project Structure=> SDK Location=> NDK Location(make sure to check one proper ndk version)

2)Project Structure=>Modules=> under NDK Version(check the same version you have added in first step) PFA image forStep2

3)Gotoyour Android studio project=> go to local.properties file=> check your ndk version number

If all 3 steps are proper with one current proper NDK version your error would have solved.

Note: make sure to sync the project files, clean project, rebuild the project.

Hope this would solve your problem!! Happy Coding:)