NDK not configured - android

Whenever I try to build my project I get this error message
"Caused by: org.gradle.api.InvalidUserDataException: NDK not configured. Download it with SDK manager. Preferred NDK version is '21.4.7075529'."
I have made sure NDK (side by side) is installed and ndk.dir=path is added to local.properties and ndkVersion is added to build.gradle. Is there anything else I'm missing??

Related

Gradle : How to automatically install CMake

I am working on an Android native project which builds using CMake.
In my build.gradle I specify :
if(project.hasProperty("native")) {
externalNativeBuild {
cmake {
path file('jni/CMakeLists.txt')
version '3.18.1+'
}
}
}
I want to invoke externalNativeBuild task from command-line only on an automated build server.
However I am getting this error:
CMake '3.18.1' or higher was not found in SDK, PATH, or by cmake.dir property.
When I build it inside Android Studio normally, It downloads and install CMake but it is not happening from command-line.
Is there a way to do it from command-line?
Android studio will automatically create a local.properties file which contains the cmake.dir property.
When you build on the build server, it's more than likely that you your source doesn't have a local.properties file as that file is not normally checked into code repositories. You'll either need to create this file or modify the PATH environment variable to include the cmake binary. This of course presumes that you have CMake installed on the build server. You can do this manually with a .zip/.tarball or if you have access to the SDK on the build server, you can install with the build tools -> How to install Android SDK Build Tools on the command line?

NDK is not installed

When building a flutter app, I get an error stating
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:extractReleaseNativeDebugMetadata'.
> NDK is not installed
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 822ms
However, the android NDK is installed.
I had the same issue. I wanted to extract the debug symbols for better debugging in the production environment.
Solution
Step 1: Installing NDK and CMAKE SDK tool from android studios (You can skip it, if already installed)
Open any project in Android studio. (Doesn't matter which project. We just want to access SDK manager)
With a project open, click Tools > SDK Manager.
Click the SDK Tools tab.
Select the NDK (Side by side) and CMake checkboxes.
Image of SDK Manager
Click OK.
A dialog box tells you how much space the NDK package consumes on disk.
Click OK.
When the installation is complete, click Finish.
Step 2
1. Check which version of NDK is installed in your system.
To check, find the NDK folder inside the Android SDK folder. For mac users, it is located at - ~/Library/Android/sdk/ndk/
You will find a folder with the NDK version name inside this directory.
For example - in my case, the installed NDK version was 23.0.7599858. So, I was able to find this directory at this location ~/Library/Android/sdk/ndk/23.0.7599858/
Note: For Ubuntu or windows users sdk/ndk directory's location will be different.
2. Ensure you have the same NDK version mentioned in the android/build.gradle file.
buildscript {
ext {
...
ndkVersion = "23.0.7599858" # the installed version of ndk.
}
...
}
EDIT:
Make sure you have ndkVersion initialized in the app/build.gradle
like this:
android {
...
ndkVersion rootProject.ext.ndkVersion
...
}
Or you can also directly write the version here like this:
android {
...
ndkVersion "23.0.7599858"
...
}
You don't have to add the ndkVersion in android/build.gradle if you do this.
Using android studio open
a. Go to settings, System settings, android sdk,on the tabs select SDK Tools confirm if NDK (side by side) and CMake Tool are installed
b. If not installed check them and press apply to download and install them.
After successfull confirmation. Open your project android folder find local.properties file, android/local.properties. You will find Something like this
Add your NDK path as follows
To find yoour NDK path
Go to home files if linux, android folder, sdk folder, inside find ndk folder, ie
/Android/Sdk/ndk/24.0.8215888
Happy Coding ! ! !
I got that error on React Native 0.64 app on AppCenter build for Android.
The solution is to go to android/app/build.gradle file and comment ndk { debugSymbolLevel 'FULL' } line if you have so (defaultConfig { ndk { debugSymbolLevel } })
The solution was found by my colleague Jose, so all credits to him)
After I added
ndk {
debugSymbolLevel 'FULL'
}
in app build.gradle file I got this error about NDK not installed.
I resolved the same problem by making this change in main build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
...
}
This Gradle upgrade forced me to upgrade the url in gradle/wrapper/gradle-wrapper.properties file
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
I have Android Studio Bumblebee 2021.1.1 Patch 3
I have only installed ndk from the android studio and
My problem just got solved, After including ...
local.properties
ndk.dir=<ANDROID_SDK>\\ndk\\XX.X.XXXXXXX
android/app/build.gradle
android {
// ...
ndkVersion "XX.X.XXXXXXX"
// ...
buildTypes{
release{
signingConfig signingConfigs.release
ndk {
debugSymbolLevel 'SYMBOL_TABLE'
}
}
}
}
This could help someone and save his/her time.
If you are using Flutter Please use this approach(according to your ndk version from checkin android studio),
it solved my problem and I used it for debug symbols native crashes
android {
...
ndkVersion "23.0.7599858"
...
}

Android Cmake 3.18.1 configuration

How to setup CMake 3.18.1 in an Android project with gradle on Android Studio?
I executed the following steps:
downloaded the CMake 3.18.1 from Android Sdk - Sdk Tools (folder appeared correctly on Android/sdk/cmake with the 3.10 and 3.6 version)
I added the version requested on build.gradle as externalNativeBuild { cmake { version "3.18.1"
I added the path on local.properties as cmake.dir=/Users/bloom/Library/Android/sdk/cmake/3.18.1
I get the error message: C/C++ release|armeabi-v7a : CMake '3.18.1' found via cmake.dir='/Users/bloom/Library/Android/sdk/cmake/3.18.1' does not match requested version '3.10.2'. and the task failed is > Task :app:generateJsonModelDebug FAILED
I suspect there is a 3.10 version hardcoded somewhere, maybe on that task. In fact, undoing point 3 and requesting version 3.6 is ignored. With 3.10 I get an error on findBoost and it clearly shows that is using the 3.10 version, as you can see Make Warning at /Users/bloom/Library/Android/sdk/cmake/3.10.2.4988404/share/cmake-3.10/Modules/FindBoost.cmake:567 (message):

Gradle sync fails with cmake "cause: executing external native build for cmake"

I'm trying to build my colleagues' project in Android Studio, which requires CMake SDK to build the external c/cpp files included in the project. The problem I'm running into is despite having installed the LLDB, NDK, and CMake SDK tools through SDK manager, the gradle for the module that references cmake path fails to sync. My colleagues who already have this project installed and working haven't run into this issue, so I suspect that it has to be something in my environment setting.
So far, I've tried uninstalling and reinstalling CMake SDK, refresh linked C++ projects, and removing the reference to the cmake path from the gradle file and adding the reference by right click the moduel -> Link C++ Project with Gradle, but none of these worked.
When I comment out the reference to my CMakeLists.txt in the gradle, it syncs, indicating that the problem is in regards to the reference to the CMake file. I also tried commenting out library references in my CMakeLists.txt file to see if the error is occurring due to a reference in the file, but even when I comment everything out, the gradle fails to sync.
This is what my gradle file looks like.
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
When I press sync (try again) in build.gradle, the error message simply shows
SIMPLE: Error configuring
When I ignore the fact that gradle sync failed and just try to build, the error message shows as this.
Cause: executing external native build for cmake <my_project_path>\src\main\cpp\CMakeLists.txt
Edit: Added a link to the image capture of my Android Studio NDK path (C:\Users\username\AppData\Local\Android\Sdk\ndk-bundle for Windows).
NDK path Capture
In short - Maybe the problem is in the build.gradle file imported together with the project.
try editing 'build.gradle' line 9: classpath 'com.android.tools.build:gradle:3.1.1'
replace the gradle version number (in my case I replaced '3.1.1' with '3.5.0').
In more detail - I had the same issue when cloning from:
https://github.com/farzaa/DracoPortedToAndroid
I did try the above (setting the ndk path) but that wasn't the problem, since the path to the ndk lib was correct. So the most probable error-cause left was some project settings imported with the cloned project.
Try comparing the "Gradle Scripts" (In the project explorer) of the imported project with a new project built in your Android Studio environment. The new project will have the correct local settings.
In my case I replaced:
classpath 'com.android.tools.build:gradle:3.1.1'
with:
classpath 'com.android.tools.build:gradle:3.5.0'
to set the NDK path in android studio go to :
file -> project structure -> sdk location -> android ndk location -> set path for example my ndk location on mac is /Users/username/Library/Android/sdk/ndk-bundle
This could be because you have a shared library in the project which needs to be linked with the shared version of the STL. Try adding the following to your build.gradle:
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
}
}
}
}
I had the same error message, and it turned out that I had a syntax error in my CMakeLists.txt
I have solved the problem by adding 'abiFilters' to app/build.gradle file:
defaultConfig {
externalNativeBuild {
cmake {
abiFilters 'armeabi-v7a','arm64-v8a'
}
}
}

NDK is not configured issue in android studio

My Application is built successfully on Eclipse but fails to Build on android studio.
It returns the error code Ndk is not Configured.
Then I've added ndk path to build.gradle then its showing the following error:
Information:Gradle tasks [:nano:assembleDebug]
WARNING [Project: :nano] Current NDK support is deprecated. Alternative will be provided in the future.
:nano:preBuild UP-TO-DATE
:nano:preDebugBuild UP-TO-DATE
:nano:compileDebugNdk
make.exe: *** No rule to make target `C:\Users\admin\nano\nano\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/la_audio_processing_android/C_\Users\admin\nano\nano\src\main\jni', needed by `C:\Users\admin\nano\nano\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/la_audio_processing_android/C_\Users\admin\nano\nano\src\main\jni\LA_PostProcessing.o'. Stop.
Error:Execution failed for task ':nano:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\admin\AppData\Local\Android\ndk\ndk-build.cmd'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 3.449 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
This is the problem faced by Android studio users in Windows environment.
First for NDK not Configured problem
Go to local.properties file and give ndk path...
for ex :
#Wed Mar 18 14:10:33 IST 2015
sdk.dir=C\:\\Users\\admin\\AppData\\Local\\Android\\sdk1
ndk.dir=C\:\\Users\\admin\\AppData\\Local\\Android\\ndk
Then for the Next Problem or Error...
Goto JNI Folder and create an empty c file by any name...
Then your problem will be solved...
Some Quick links about this are
http://ph0b.com/android-studio-gradle-and-ndk-integration/
And
https://code.google.com/p/android/issues/detail?id=66937
Go to option File->Project Structure
Select SDK Location->Android NDK Location and choose NDK listed in dropdown
For whatever reason, setting ndk.dir on the properties file is not working for me. However, setting/exporting the variable ANDROID_NDK_HOME prior to launching android studio did the trick.
Bash syntax (paths below are specific to my installation)
export ANDROID_HOME=/opt/android-sdk-linux
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
Environment
Ubuntu Linux x64/GNU bash, version 4.4/Android Studio 2.2.3
Goto Files -> Project Structure -> SDK Location
Android NDK Location is at the bottom right of the window.
I use Android Studio 1.4.1.
Below is my local.properties
ndk.dir=C:\Users\BestQ\AppData\Local\Android\Sdk\ndk-bundle
sdk.dir=C:\Users\BestQ\AppData\Local\Android\Sdk
It work well.
In build.gradle use
android {
ndkVersion '21.1.6352462'
}
and use android.useDeprecatedNdk=true in gradle.properties
In some cases, you need to point exact version of ndk version on the local.properties file like that:
ndk.dir=/Users/ali6p/Library/Android/sdk/ndk/21.3.6528147
If you need to install a specific version of ndk bundle, open Android Studio preferences and install the version (Preferences > Appearance & Behaviour > System Settings > Android SDK > SDK Tools: Show Package Details > NDK (Side by side): check the version:
My issue was caused by the target file not being found (in my case, a git sub-module needed to be checked out), so ensure all the referenced files exist on the specified path.
Maybe the NDK is not installed.
If it's the case, go to SDK Manager (top-right icon).
Go to Android SDK > SDK Tools
Check NDK (Side by side) and install it.

Categories

Resources