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?
Related
I have a simple react-native project when I try to build an android release version of the application, I face this error message:
Caused by: java.lang.RuntimeException:
org.gradle.api.InvalidUserDataException: NDK not configured. Download
it with SDK manager. Preferred NDK version is '21.4.7075529'
I made a Keystore and set password like android studio to get a release and debug apk.
I tried this until now:
I tried to set NDK in android studio but couldn't build the project.
I also modified build.gradle to build the project but was unsuccessful.
I put my singingConfig and buildTypes and also stackTrace below.
my keystore data
singingConfig and buildTypes
What went wrong:
A problem occurred evaluating project ':expo'.
A problem occurred configuring project ':expo-modules-core'.
Failed to notify project evaluation listener.
> org.gradle.api.InvalidUserDataException: NDK not configured. Download it with SDK manager. Preferred NDK version is '21.4.7075529'.
> Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
Open root folder projectname > android > open local.properties > copy and paste below lines after sdk.dir (if you don't have a local.properties file copy the below file and change SDK path according to your operating system.)
sdk.dir=/Users/yourusername/Library/Android/sdk
ndk.dir=/Users/yourusername/Library/Android/sdk/ndk/21.4.7075529 (You should find this version in the NDK folder and the path will vary depending on your operating system.);
I solved this problem using another way to get release version of the apk.
I used eas build -p android or expo build:android and finally after a really long time expo generates apk on his website. But it was too large application about 60mg and I'm trying to reduce it's size.
eas build -p android this command is for abb version
expo build:android this is for apk release.
but unfortunately, I Couldn't use gradle in order to release apk.
I am working on an android project which use C++ code.
I have added required CMake settings in build.gradle:
externalNativeBuild {
cmake {
path file('jni/CMakeLists.txt')
version '3.18.1'
}
}
But the problem is there are a lot of C++ files. Using gradle for build makes Android Studio index those files and it makes IDE very slow.
Is there a way to invoke CMake task manually outside IDE so that IDE don't index them? Actually what I want is to use a gradle task to build native code via CMake.
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"
...
}
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):
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'
}
}
}