简体   繁体   中英

How to fix android studios 2.3 NDK bug?

I'm assuming it's a bug since I didn't have any problems until the new update. So I cant use the gradle console to debug my app because I have this warning -

"Configuration on demand is an incubating feature. NDK is missing a "platforms" directory. If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\\Users\\Emily Thacker\\AppData\\Local\\Android\\Sdk\\ndk-bundle. If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning."

I am pretty sure I am not using NDK and I dont see how I can fix this problem here is my local.properties

## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C\:\\Users\\Emily Thacker\\AppData\\Local\\Android\\Sdk

Also I do not see a ANDROID_NDK_HOME file in my directory.

I was able to prevent this annoying message; here is what worked for me.

BACKGROUND:

  1. I am not using the NDK at all, and had never installed the NDK.

  2. However, as mentioned in another answer here by xsveda, this is a Gradle bug that is documented here:

    https://code.google.com/p/android/issues/detail?id=228424

    and so even the "NDK-innocent" may become its victims.

  3. The problem is that Gradle is computing the location of an NDK folder by just tacking on the string "/ndk-bundle" to the SDK folder location, even if you have never installed the NDK.

  4. After establishing this false expectation of an NDK folder existing in a particular location, each time you build, Gradle gives you a warning that you're "missing" that folder. This is just a warning and does not prevent your build from completing, but it is annoying.

HOW I STOPPED THE ANNOYING MESSAGE:

Since disk space is cheap, and my time is precious to me, I humored this bug by installing the NDK, even though I do not intend to use it.

To do this, you can go to:

File -> Project Structure -> SDK Location

and look in the Android NDK location field. If you have not installed the NDK, this field will be empty.

In that case, below that field will be a link for installing the NDK. Click on that link and install it. It takes a few minutes.

Once the installation completes and you close the installation progress dialog, the location of the NDK will be automatically written into the Android NDK location field. This will be something like:

C:\\dev\\astudiosdk\\ndk-bundle

Click the OK button and build again. The error disappears.

Note that you may be able to just type the expected folder into this field; I did not try that. But I don't know whether that might cause some other problems, especially if you eventually decide to actually use the NDK.

Just install the Android NDK .

That fixed my error and warning!

https://i.stack.imgur.com/Lsu8E.png

  1. Go to T ools -> Android -> SDK Manager
  2. Click SDK Tools
  3. CHECK NDK
  4. Apply and quit.

Sounds like maybe updating SDK from Android Studio IDE could help

Steps are:

  1. Go to Tools (top-menu item) > Android > SDK Manager
  2. Click SDK Tools tab
  3. Scroll down to the NDK checkbox update-option

Screen shots here: How to update Android NDK in place?

Fixed this issue by removing an empty ndk-bundle folder from SDK root folder (have no idea why and when it has appeared):

android SDK文件夹中的ndk-bundle文件夹

Here is the explanation why it helps from the issue on Android bug tracker :

For anyone still experience this issue on plugin 3.0.0-alpha1 or later. Please file a new bug and try to answer all question in #33. We need more information to debug the problem and adding comments to a closed bug is an easy way for it to get lost.

To give a bit of background, the plugin checks whether the NDK directory is valid. Most likely, you are not using NDK. We automatically assume it's in {sdk}/ndk-bundle. It will be ignored if {sdk}/ndk-bundle does not exist. If you see 'NDK is missing a "platforms" directory.', it means there is an {sdk}/ndk-bundle, but not a {sdk}/ndk-bundle/platforms directory. This means you have a corrupted NDK for some reason. It is safe to just remove {sdk}/ndk-bundle if you are not using it.

You can give it a try :

There is a checkbox for it in android studio already.

Android Studio -> Preferences -> Compiler -> Gradle -> Command-line Options -> Configure on Demand

Uncheck it and then sync gradle again

在此处输入图片说明

I faced this problem:

NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /Users/<user_name>/Library/Android/sdk/ndk-bundle.

and I solved it by creating one empty platforms folder in ndk-bundle folder. Like: path/to/your/Android/sdk/ndk-bundle/platforms .

In case you do not have ndk-bundle folder. Install NDK by following steps ( Install NDK screenshot ) :

  • Open Preferences
  • Go to Android SDK from left menu.
  • Select SDK Tools .
  • Check NDK.
  • Apply and OK.

Gradle version: 6.3

Android studio version: Android Studio 4.1.1 Build #AI-201.8743.12.41.6953283, built on November 5, 2020

PS: I did manual installation of gradle from: https://docs.gradle.org/current/userguide/installation.html

You should not use a directory path with spaces for Android SDK. As an easy cure you can manually change

sdk.dir=C:/Users/EMILYT~1/AppData/Local/Android/Sdk

You don't need to install NDK.

This type of error statement are:-

  1. NDK is missing a "platforms" directory.
  2. How to set ANDROID_NDK_HOME so that Android Studio does not ask for ndk location?

Solution :

Open your build.gradle and here you are see two gradle path like: classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.2.0'

You can remove one of those classpath and keep only one Classpath.

Clean the project gradlew clean

This is working for me never require to set the ndk path or the ndk setting.

Android Studio NDK 2.3 BUG

在 Android Studio SDK 工具中更新 NDK 解决了我的问题。

For me, the NDK error turned out to be a false diagnosis. This error occurred when gradle threw a ClassNotFound exception on java.io.UncheckedIOException class.

Although the class is defined in Java 8, it was not included in the JDK 1.8.0u51 (or presumably earlier versions) which I had installed.

Updating the JDK and removing the 1.8.0u51 version resolved the issue.

If you cannot build your project while releasing APK

That warning you see is just a warning. Whats funny is that its most likely you left some languages strings.xml without required names. Or some of localized strings-.xml has unwanted characters like " ' " which should be leplaced with eg " \\' " . Overall it can be related to your app resources. Recheck them carefully first.

Go to Gradle Scripts then to local.properties and set the SDK , and NDK locations properly, in my case the setting is:

ndk.dir=F:\\AndroidSDK\\ndk-bundle sdk.dir=F:\\AndroidSDK

I don't know if this would help anyone but I was getting the same error and nothing worked. And I went down to ndk folder created an empty platforms directory and it worked.

In my case, I found that my project is not using NDK-bundle SDK. So, I mainly deleted ndk-bundle in

path/to/your/Android/sdk/

I got the resolution.

In my case I had to downgrade my NDK from 22.1.7171670 to 21.4.7075529. I've learnt this resolution from this link

If you do need to use NDK in your project you need to create the platforms folder and put the NDK there.

  1. Go ahead and create platforms folder under your SDK directory. In my case it was under: C:\\Users\\K\\AppData\\Local\\Android\\Sdk\\ndk-bundle\\platforms
  2. Then download the NDK for your OS from here: https://developer.android.com/ndk/downloads . In my case it's Windows, so the file should be named something like this: android-ndk-r21e-windows-x86_64.zip
  3. Paste and unarchive the NDK into the platforms folder在此处输入图片说明
  4. Sync gradle.

This bug is still comes even if you have classpath 'com.android.tools.build:gradle:3.2.1' ,i mean 3+ so change this to the latest and also change to distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-all.zip to distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip this or latest and if problem still presist.

Remove Andorid_NDK_HOME form Env variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM