首页 > 解决方案 > Can not set the path of NDK in project structure in Android studio

问题描述

I am using the latest version of Android studio V4.1 to implement my project on Windows 10. The project also requires Java 11 and Ndk libraries.

First, I installed NDK V22 and V16 as well as Cmak from SDK tools in SKD manger as shown below: enter image description here

Then, Installed Java 11 from Oracel.com, and checked using cmd as shown below:

enter image description here

I added the paths of SDK and NDK to the local.properties files as follows:

sdk.dir=C\:\\Users\\user_name\\AppData\\Local\\Android\\Sdk
ndk.dir=C\:\\Users\\user_name\\AppData\\Local\\Android\\Sdk\\ndk\\22.0.7026061

Also, added JAVA_HOME and ANDROID_NDK_HOME in the system environment.

The problem is that I can not locate the NDK path from the "File > project structure> Android NDK location" in the Android project to tell the Android studio where is the NDK is located. It always shows as inactive and can not browse the path as shown in the below picture:

enter image description here

Info: Android Gradle Plugin Version 4.1.1

Gradle Version 6.8

Can anyone help to fix this problem?

标签: javaandroid-studioandroid-ndkenvironment-variables

解决方案


This was moved to the build.gradle to keep builds reproducible: https://developer.android.com/studio/releases/gradle-plugin#ndk-path

It's not in the UI because you should almost never use it. You should be using android.ndkVersion in almost all cases. android.ndkPath (and ndk.dir) is just a way to make builds non-reproducible/non-portable.

The cases where android.ndkPath makes sense are if your CI service only has the NDK installed to a specific location not known to the SDK, or if you're using an unreleased NDK.


推荐阅读