Gradle sync failed, NDK not configured, download it with SDK manager

冷暖自知 提交于 2020-06-24 04:39:56

问题


I am completely new to Android development and just installed Android Studio. I'm doing a very basic HelloGL2 exercise, and I opened up the HelloGL2.iml file. I tried running it, but it said that the gradle project sync failed and that the NDK is not configured. In the simplest terms (to a complete beginner in Android), how do I fix this?


回答1:


disclaimer: I work on Android Studio

With newer version (3.6+) of Android Gradle Plugin, please download with "NDK (Side by side)" option from the SDK manager and then specify ndkVersion in the build.gradle with the full version of NDK that is locally available from your machine.

For example, after you downloaded NDK 20.1.5948944 under "NDK (Side by side)" from the SDK manager, the downloaded NDK would be, by default, under ~/Android/Sdk/ndk/20.1.5948944. Then in your module level build.gradle, you need something like the following.

android {
    compileSdkVersion 29


    defaultConfig {
        // ...
    }

    buildTypes {
        // ...
    }

    externalNativeBuild {
        // ...
    }

    ndkVersion "20.1.5948944" // <<==== Here
}



回答2:


I double-checked that I already had the latest NDK installed (so that wasn't the solution for me). Next I did the following: Android Studio Menu -> File -> Project structure -> SDK Location. Here, no NDK was selected, so I selected the latest version. This solved the problem.

This fix only works locally for this particular machine and for this project by writing your choice to the local.properties file in your project's root.

UPDATE: There's also a way to set this globally via ANDROID_NDK_HOME environment variable. This is how I invoke building my project on a build server:

export ANDROID_SDK_ROOT=/home/jenkins/Android/Sdk/; export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/21.0.6113669; ./gradlew assembleRelease



回答3:


You can install these components using the SDK Manager:

  1. From an open project, select Tools > Android > SDK Manager from the main menu.
  2. Click the SDK Tools tab.
  3. Check the box next to NDK, CMake, and LLDB
  4. Click apply

(Using Android Studio 3.6.1)

Edit: Following above process on later versions of Android Studio still gives an NDK not installed error during the build process. This answer given by Violet Giraffe solved the issue. Once the necessary files are installed, go to File > Project Structure > SDK and select the NDK version.

See this guide for more details.




回答4:


//Try this one 1 - Android Studio -> Tools -> SDK Manager -> select SDK Tools

2 - Check the boxes next to LLDB, CMake, and NDK

3 - Apply and press OK button ..




回答5:


if you see this error you may have not any NDK in your SDK.

so you better download it from hereand copy all folders and files in your SDK.

also you can go; open project>select tools[in upper page]>Android>SDK Manager[from main menu]>click SDK Tools tab>and check the box next to NDK

if you have not NDK in SDK Tools tab,you can download automatic in this folder




回答6:


with android studio 3.0 + this issue is approached differently.

Go to File > Settings > Android SDK > and select the SDK entry and update. It should fix the issue.

the other approach to the same problem is when you do a gradle project sync it will automatically identify the issue of requiring version upgrade and provide you clickable link in the console. Through these steps it might also prompt you to update other dependencies, such as CMake.




回答7:


My version is a little bit different :

From an open project, select Tools > Android > SDK Manager from the main menu. In Appearance & behavior > System Settings > Android SDK I have to Click the SDK Tools tab. Check the box next to NDK Click apply



来源:https://stackoverflow.com/questions/40943764/gradle-sync-failed-ndk-not-configured-download-it-with-sdk-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!