Introduction:
- Briefly explain the issue faced by developers after updating to Android Gradle plugin 3.6.0.
- Mention the error message: “No version of NDK matched the requested version 20.0.5594570.”
Explaining the Issue:
- Discuss why the error occurs and what it means for the project.
- Mention the available local versions and the requested version.
- Explain the significance of the NDK in the project and its role in building native libraries.
Solutions:
1: Selecting the Locally Installed NDK:
- Explain how to open the Project Structure Dialog in Android Studio.
- Guide users to navigate to SDK Location and select the locally installed version of NDK.
- Provide step-by-step instructions or screenshots to make it easier for readers to follow.
2: Specifying NDK Version in Module Gradle Script:
- Explain how developers can specify the NDK version in the module’s build.gradle file.
- Provide a code snippet that shows how to add the ndkVersion property in the android{} block.
- Mention the benefits of this approach for maintaining consistency across different machines.
3: Setting the ANDROID_NDK_HOME Environment Variable:
- Explain how developers can set the ANDROID_NDK_HOME environment variable.
- Provide the necessary steps for different operating systems (Windows, macOS, Linux).
- Highlight any potential considerations or limitations of this approach.
To resolve this issue
You have several options available to you. The first option is to select the locally installed NDK version in the Project Structure Dialog. This method is suitable for local builds and can be done by following these steps:
- Open Android Studio and navigate to “File” > “Project Structure…” or use the hotkeys “CTRL + ALT + SHIFT + S” (on Windows) to open the Project Structure Dialog.
- In the dialog, go to “SDK Location” and select the locally installed version of NDK under “Android NDK Location.” Typically, the NDK is installed in the user folder, followed by “\AppData\Local\Android\Sdk\ndk%ndk version%” for Windows users.
- Save the changes and rebuild your project.
NDK version in the Project Structure Dialog
You can ensure that the build process uses the correct NDK version and resolves the error.
If you want to specify a specific NDK version in your project consistently across different machines, you can use the second option. This involves adding the ndkVersion
property in your module’s build.gradle
file. Here’s how you can do it:
- Open your project in Android Studio and navigate to the module’s
build.gradle
file. - Inside the
android
block, add the following line:ndkVersion "major.minor.build"
, replacing the string between the double quotes with the desired NDK version. For example,ndkVersion "21.0.6113669"
sets the NDK version to 21.0.6113669. - Save the changes and rebuild your project.
Explicitly specifying the ndkVersion
in your build.gradle
file,
You ensure that the build process uses the desired NDK version consistently.
Another option is to set the ANDROID_NDK_HOME
environment variable on the machine where you build your project. This approach is useful when you want all projects built on a particular machine to use the same NDK version. Here’s how you can set the ANDROID_NDK_HOME
variable:
- Determine the path to the NDK folder on your machine.
- Set the
ANDROID_NDK_HOME
environment variable to the path of the NDK folder.- On Windows: Open the System Properties dialog, go to the “Advanced” tab, and click on the “Environment Variables” button. In the “System variables” section, click “New” and enter
ANDROID_NDK_HOME
as the variable name and the path to the NDK folder as the variable value. - On macOS and Linux: Open the terminal and run the following command, replacing
<ndk-path>
with the actual path to the NDK folder:arduinoCopy codeexport ANDROID_NDK_HOME=<ndk-path>
- On Windows: Open the System Properties dialog, go to the “Advanced” tab, and click on the “Environment Variables” button. In the “System variables” section, click “New” and enter
By setting the ANDROID_NDK_HOME
environment variable, you specify the NDK version to be used across all projects built on that machine.
It’s worth noting that starting from Android Gradle plugin 4.1.0, the default NDK version is automatically downloaded, removing the need to manually download the default version. This enhancement simplifies the process of managing NDK versions in your projects.
Conclusion:
- Recap the solutions discussed and their respective benefits.
- Mention the importance of resolving the NDK version mismatch issue for successful project builds.
- Encourage readers to choose the solution that best suits their needs and project requirements.
Resolving the “No version of NDK matched the requested version” error involves selecting the correct NDK version in the Project Structure Dialog, specifying the NDK version in the module’s build.gradle
file, or setting the ANDROID_NDK_HOME
environment variable. Choose the option that best suits your project’s requirements and ensures consistency in the build process.