简体   繁体   English

如何修复 android studios 2.3 NDK 错误?

[英]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 -所以我不能使用 gradle 控制台来调试我的应用程序,因为我有这个警告 -

"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." “按需配置是一个孵化功能。NDK 缺少“平台”目录。如果您使用 NDK,请验证 ndk.dir 设置为有效的 NDK 目录。当前设置为 C:\\Users\\Emily Thacker\\ AppData\\Local\\Android\\Sdk\\ndk-bundle。如果您没有使用 NDK,请从 ANDROID_NDK_HOME 或 local.properties 中取消设置 NDK 变量以消除此警告。”

I am pretty sure I am not using NDK and I dont see how I can fix this problem here is my local.properties我很确定我没有使用 NDK,我不知道如何解决这个问题,这是我的 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.此外,我在我的目录中没有看到 ANDROID_NDK_HOME 文件。

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.我根本没有使用 NDK,也从未安装过 NDK。

  2. However, as mentioned in another answer here by xsveda, this is a Gradle bug that is documented here:但是,正如 xsveda 在此处的另一个答案中所述,这是此处记录的 Gradle 错误:

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

    and so even the "NDK-innocent" may become its victims.因此,即使是“NDK 无辜者”也可能成为其受害者。

  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.问题是 Gradle 只是通过将字符串“/ndk-bundle”附加到 SDK 文件夹位置来计算 NDK 文件夹的位置,即使您从未安装过 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.在建立对存在于特定位置的 NDK 文件夹的这种错误期望之后,每次构建时,Gradle 都会警告您“丢失”了该文件夹。 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.由于磁盘空间很便宜,而且我的时间对我来说很宝贵,我通过安装 NDK 解决了这个错误,即使我不打算使用它。

To do this, you can go to:为此,您可以访问:

File -> Project Structure -> SDK Location文件 -> 项目结构 -> SDK 位置

and look in the Android NDK location field.并查看 Android NDK 位置字段。 If you have not installed the NDK, this field will be empty.如果您尚未安装 NDK,则此字段将为空。

In that case, below that field will be a link for installing the NDK.在这种情况下,该字段下方将是用于安装 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.安装完成并关闭安装进度对话框后,NDK 的位置将自动写入 Android NDK 位置字段。 This will be something like:这将类似于:

C:\\dev\\astudiosdk\\ndk-bundle 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.但我不知道这是否会导致一些其他问题,尤其是如果您最终决定实际使用 NDK。

Just install the Android NDK .只需安装Android NDK

That fixed my error and warning!这修复了我的错误和警告!

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

  1. Go to T ools -> Android -> SDK Manager转到ools -> Android -> SDK Manager
  2. Click SDK Tools单击SDK Tools
  3. CHECK NDK检查NDK
  4. Apply and quit.申请并退出。

Sounds like maybe updating SDK from Android Studio IDE could help听起来从 Android Studio IDE 更新 SDK 可能会有所帮助

Steps are:步骤是:

  1. Go to Tools (top-menu item) > Android > SDK Manager转到Tools (top-menu item) > Android > SDK Manager
  2. Click SDK Tools tab单击 SDK 工具选项卡
  3. Scroll down to the NDK checkbox update-option向下滚动到NDK复选框更新选项

Screen shots here: How to update Android NDK in place?此处的屏幕截图: 如何就地更新 Android NDK?

Fixed this issue by removing an empty ndk-bundle folder from SDK root folder (have no idea why and when it has appeared):通过从 SDK 根文件夹中删除一个空的ndk-bundle文件夹来修复此问题(不知道它出现的原因和时间):

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

Here is the explanation why it helps from the issue on Android bug tracker :这是为什么它有助于解决 Android 错误跟踪器上的问题的解释:

For anyone still experience this issue on plugin 3.0.0-alpha1 or later.对于仍然在插件 3.0.0-alpha1 或更高版本上遇到此问题的任何人。 Please file a new bug and try to answer all question in #33.请提交一个新的错误并尝试回答 #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.为了提供一些背景知识,该插件会检查 NDK 目录是否有效。 Most likely, you are not using NDK.很可能,您没有使用 NDK。 We automatically assume it's in {sdk}/ndk-bundle.我们自动假设它在 {sdk}/ndk-bundle 中。 It will be ignored if {sdk}/ndk-bundle does not exist.如果 {sdk}/ndk-bundle 不存在,它将被忽略。 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.如果您看到“NDK 缺少“平台”目录。”,这意味着存在 {sdk}/ndk-bundle,但没有 {sdk}/ndk-bundle/platforms 目录。 This means you have a corrupted NDK for some reason.这意味着由于某种原因,您的 NDK 已损坏。 It is safe to just remove {sdk}/ndk-bundle if you are not using it.如果您不使用 {sdk}/ndk-bundle,则删除它是安全的。

You can give it a try :你可以试一试:

There is a checkbox for it in android studio already. android studio 中已经有一个复选框。

Android Studio -> Preferences -> Compiler -> Gradle -> Command-line Options -> Configure on Demand Android Studio -> 首选项 -> 编译器 -> Gradle -> 命令行选项 -> 按需配置

Uncheck it and then sync gradle again取消选中它然后再次同步gradle

在此处输入图片说明

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.我通过在ndk-bundle文件夹中创建一个空的platforms文件夹来解决它。 Like: path/to/your/Android/sdk/ndk-bundle/platforms .像: path/to/your/Android/sdk/ndk-bundle/platforms

In case you do not have ndk-bundle folder.如果您没有 ndk-bundle 文件夹。 Install NDK by following steps ( Install NDK screenshot ) :按照以下步骤安装 NDK安装 NDK 截图):

  • Open Preferences打开Preferences
  • Go to Android SDK from left menu.从左侧菜单转到Android SDK
  • Select SDK Tools .选择SDK Tools
  • Check NDK.检查 NDK。
  • Apply and OK.申请并确定。

Gradle version: 6.3摇篮版本:6.3

Android studio version: Android Studio 4.1.1 Build #AI-201.8743.12.41.6953283, built on November 5, 2020 Android Studio 版本:Android Studio 4.1.1 Build #AI-201.8743.12.41.6953283,2020年11月5日构建

PS: I did manual installation of gradle from: https://docs.gradle.org/current/userguide/installation.html PS:我从以下位置手动安装了 gradle: https ://docs.gradle.org/current/userguide/installation.html

You should not use a directory path with spaces for Android SDK.您不应为 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.您不需要安装 NDK。

This type of error statement are:-这种类型的错误语句是:-

  1. NDK is missing a "platforms" directory. NDK 缺少“平台”目录。
  2. How to set ANDROID_NDK_HOME so that Android Studio does not ask for ndk location?如何设置 ANDROID_NDK_HOME 以便 Android Studio 不要求 ndk 位置?

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'打开你的build.gradle ,在这里你会看到两个 gradle 路径,如: 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清理项目gradlew clean

This is working for me never require to set the ndk path or the ndk setting.这对我有用,从不需要设置 ndk 路径或 ndk 设置。

Android Studio NDK 2.3 BUG Android Studio NDK 2.3 BUG

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

For me, the NDK error turned out to be a false diagnosis.对我来说,NDK 错误原来是一个错误的诊断。 This error occurred when gradle threw a ClassNotFound exception on java.io.UncheckedIOException class.当 gradle 在java.io.UncheckedIOException类上抛出ClassNotFound异常时发生此错误。

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.尽管该类是在 Java 8 中定义的,但它并未包含在我安装的 JDK 1.8.0u51(或者可能是更早的版本)中。

Updating the JDK and removing the 1.8.0u51 version resolved the issue.更新 JDK 并删除 1.8.0u51 版本解决了该问题。

If you cannot build your project while releasing APK如果您在发布 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.有趣的是,您很可能留下了一些没有必需名称的语言 strings.xml。 Or some of localized strings-.xml has unwanted characters like " ' " which should be leplaced with eg " \\' " .或者一些本地化的 strings-.xml 有不需要的字符,比如“ ' ”,应该用例如“ \\' ”来代替。 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:转到 Gradle Scripts 然后转到 local.properties 并正确设置 SDK 和 NDK 位置,在我的情况下设置是:

ndk.dir=F:\\AndroidSDK\\ndk-bundle sdk.dir=F:\\AndroidSDK 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.我去 ndk 文件夹创建了一个空的平台目录,它工作正常。

In my case, I found that my project is not using NDK-bundle SDK.就我而言,我发现我的项目没有使用 NDK-bundle SDK。 So, I mainly deleted ndk-bundle in所以,我主要是删除了ndk-bundle

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.就我而言,我不得不将 NDK 从 22.1.7171670 降级到 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.如果确实需要在项目中使用 NDK,则需要创建platforms文件夹并将 NDK 放在那里。

  1. Go ahead and create platforms folder under your SDK directory.继续并在您的 SDK 目录下创建platforms文件夹。 In my case it was under: C:\\Users\\K\\AppData\\Local\\Android\\Sdk\\ndk-bundle\\platforms就我而言,它位于: 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 .然后从这里下载适用于您的操作系统的 NDK: 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就我而言,它是 Windows,因此该文件应命名为: android-ndk-r21e-windows-x86_64.zip
  3. Paste and unarchive the NDK into the platforms folder将 NDK 粘贴并解压到platforms文件夹中在此处输入图片说明
  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.即使您有类路径 'com.android.tools.build:gradle:3.2.1' ,此错误仍然存​​在,我的意思是 3+,因此将其更改为最新版本并更改为 distributionUrl=https://services.gradle。 org/distributions/gradle-5.6.4-all.zip 到 distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip 这个或最新的,如果问题仍然存在。

Remove Andorid_NDK_HOME form Env variable移除 Andorid_NDK_HOME 表单环境变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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