How do I parallelize externalNativeBuild for different ABIs? - android

Background
I'm currently working on an Android project which contains a fair amount of native code. The native code is built for multiple ABIs. For various reasons, the native code has up until now been built using a custom Gradle task that invokes ndk-build.cmd.
Now I'm in the process of changing this to use externalNativeBuild for the NDK integration, and CMake lists instead of the old Android.mk files. It seems like the better supported/documented way of doing things.
Problem
One nice thing about the old ndk-build method was that it would build for multiple ABIs in parallel - e.g. an ARM version and an x86 version of the library could be built in parallel.
This is especially helpful in my case, because I am required to use a 3rd party tool during the linking phase which 1) takes a very long time (minutes) to finish, and 2) is mostly single-threaded. Hence, building the library for multiple ABIs in parallel helped shorten my build times a lot.
When building with CMake / Ninja I cannot replicate this behavior. Ninja is supposed to parallelize builds by default, and it may well be doing that for a given ABI (i.e. compiling multiple source files in parallel for the same ABI). But from what I can tell, it never starts building the library for another ABI until it has finished building for the current ABI.
Question
When using CMake / Ninja through externalNativeBuild, is there any way I can tell the build system that I want it to build my native code for multiple ABIs in parallel?
Example
A minimal example to demonstrate this is as simple as the "New project" template in Android Studio, i.e. something like:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib SHARED
src/main/cpp/native-lib.cpp )
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.cmakemultiabis"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
And then building with e.g. gradlew assembleRelease will give you:
> Task :app:externalNativeBuildRelease
Build native-lib x86
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\release\obj\x86\libnative-lib.so
Build native-lib armeabi-v7a
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\release\obj\armeabi-v7a\libnative-lib.so
It may not be obvious from that output that the two libraries are built sequentially, but it does become obvious if you have something that takes a noticeable amount of time to link.
I have tried this both with the CMake / Ninja versions that you can download with the SDK Manager, as well as some newer versions (CMake 3.12.3, Ninja 1.8.2), and saw the same behavior in both cases.

Related

Debugger fails on documentation JNI C++ example (Windows and CMake)

Windows 7.
Android Studio Chipmunk 2021.2.1 Patch 2.
CMake.
Debugging "java only" apps works ok on the Nexus 5X.
Created the JNI C++ example (see https://developer.android.com/studio/projects/add-native-code#new-project).
CMakeLists.txt and gradle files all as generated.
App runs ok on Nexus 5X via USB.
Starting with debugger fails with the message:
Debugger process finished with exit code -1073741515 (0xC0000135). A library required by the native debugger might be missing on your system.
Which library "might be missing" and on which "system" Android Studio or Nexus 5X?
build.gradle (app):
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.testcpp2"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ''
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
CMakeLists.txt:
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project("testcpp2")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
testcpp2
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
testcpp2
# Links the target library to the log library
# included in the NDK.
${log-lib})
Thanks.

Why does Prefab NDK Dependencies not work?

I have some native code that depends on OpenSSL. In the beginning, I tried manually compiling OpenSSL for Android, but it simply wouldn't find the definitions.
Then I decided to move on and try using Prefabs instead. I followed the example Android NDK Prefab example, but it just doesn't work.
My CMakeLists contains the following
find_package(openssl REQUIRED CONFIG)
target_link_libraries(
testproject
openssl::openssl)
My build.gradle:
android {
compileSdk 31
defaultConfig {
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
prefab true
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.android.ndk.thirdparty:openssl:1.1.1l-beta-1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
But whenever I compile, I get
Could not find a package configuration file provided by "openssl" with any
of the following names:
opensslConfig.cmake
openssl-config.cmake
Looking into the downloaded data, I see the openSSL folder under cmake only contains opensslConfigVersion.cmake and not opensslConfig.cmake, as it does with curl, for example.
What is going on? Why is this not working? Any help is appreiciated.
The curl-ssl example in the [ndk samples](gitclo https://github.com/android/ndk-samples)
only builds because it allows C++ and STL.
But openssl is C only.
The maven repo ndk thirdparty
links to the sources for the prefab package for openssl and curl among others,
i.e. ndkports.
There is no reference to C++ there for openssl.
It seems the problem is by prefab.
I found this issues: OpenSSL forces c++_shared – why?
Judging from this and other issues there is a high chance that prefab might just not fit your and my project as of yet.
You don't get an according curl message, because curl depends on openssl,
which makes the latter build first.
If you remove openssl you get:
Error: curl depends on unknown dependency openssl
I first did have no ndkVersion defined, as you.
Only afterward I got more error messages:
... //openssl/crypto. Rejected the following libraries:
C/C++: prefabandroid.arm64-v8a: User is targeting armeabi-v7a but library is for arm64-v8a
Removing armeabi-v7a from
ndk.abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
I got
... //openssl/ssl. Rejected the following libraries:
C/C++: prefabandroid.arm64-v8a: User requested no STL but library requires libc++
C/C++: prefabandroid.armeabi-v7a: User is targeting arm64-v8a but library is for armeabi-v7a
Another sign that prefab is ealily getting confused.
And because it was not built finally:
Could not find a package configuration file provided by "openssl" with any
of the following names:
··
opensslConfig.cmake
openssl-config.cmake
The file refers to
app/.cxx/cmake/debug/prefab/arm64-v8a/prefab/lib/aarch64-linux-android/cmake/openssl/opensslConfig.cmake
This has links that point to ~/.gradle.
So the include and link directories are somewhere deep down in ~/.gradle and not under the project directory.
One can include native code directly via cmake.
The ndkports are a starting point for to configuration.

App works fine on emulators, but crashes on device with: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__aeabi_memcpy"

I'm trying to implement yctung's AndroidLibSvm into my project with Android Studio 3.2.1. While the app works fine on any emulated device (I tried Android 23 and 28, both worked flawlessly), it crashes on my real device (a lenovo tablet with Android 6.0) with the following error:
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__aeabi_memcpy" referenced by "/data/app/com.krautkremer.nils.mymirror-2/lib/arm/libjnilibsvm.so"
as soon as the app tries to run the part of the code that uses cytung's lib.
There are a few similar cases on SO e.g. here or here but setting my
arguments "-DANDROID_PLATFORM=android-23"
or any other android-x and my targetSdkVersion to 23 in the build.gradle didn't solve it.
this is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.krautkremer.nils.mymirror"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
arguments "-DANDROID_PLATFORM=android-23"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
//exclude 'META-INF/proguard/androidx-annotations.pro'
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.media:media:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation 'androidx.annotation:annotation:1.0.1'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
implementation 'com.google.firebase:firebase-ml-common:16.1.6'
implementation 'com.google.firebase:firebase-ml-vision-face-model:17.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1-alpha01'
implementation project(':androidlibsvm-release')
}
apply plugin: 'com.google.gms.google-services'
I even downgraded my NDK version from 18 to 15 with no success.
Any ideas what might be the problem?
Help me, Obi-Wan Kenobi. You're my only hope.
EDIT:
This is my CMakeLists.txt, if it is of any help. I didn't change anything, should I?
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib})
Try to change your minSdkVersion and targetSdkVersion, i.e.
minSdkVersion 15
targetSdkVersion 23

Vulkan CMakeLists.txt?

I'm trying to make an android application that uses the Vulkan API for rendering, but I always get the "undefined reference to 'vkCreateInstance'" message.
Here is my CMakeList.txt:
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib
SHARED
src/main/cpp/native-lib.cpp)
add_library( vulkan_activity
SHARED
src/main/cpp/vulkan_activity.cpp)
add_library( vulkan_stuff
SHARED
src/main/cpp/vulkan_stuff.cpp)
add_library( vulkan_buffers
SHARED
src/main/cpp/vulkan_buffers.cpp)
find_library( log-lib
log )
target_link_libraries( native-lib
vulkan_stuffx
vulkan_activity
vulkan_buffers
vulkan
${log-lib})
And this is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.game.productions.phenyl.futuroland"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions -v"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-location:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
I want to build my application from scartch, so I don't want get anwsers like use the samples.
Android only has libvulkan.so on API 26 and higher (Nougat). Some devices supported it on Marshmallow, but you're not guaranteed that libvulkan.so will be present on API < 26, so the NDK won't let you link against it unless your NDK target platform is >= 26, since otherwise your app won't even launch on many of the devices that you say you want to be able to run on (minSdkVersion 16).
If you set minSdkVersion to 26, your native code should build against that version of the NDK headers/libraries, and libvulkan.so will be available at link time.
Or, if you're careful to only try to load your shared library that links against libvulkan.so when you're running on a Nougat device, you could leave minSdkVersion alone and add externalNativeBuild { cmake { arguments "-DANDROID_PLATFORM=android-26" } }. You'll want to carefully test on pre-Nougat devices or emulator images, since it's easy to accidentally end up with library dependencies that don't exist on earlier versions of the OS.
Or, instead of linking against libvulkan.so directly, you can use dlopen to load libvulkan.so at runtime, with a fallback or graceful exit if it fails, and then use dlsym() to get a pointer to vkGetInstanceProcAddr, and load everything else using that. This is the only way to use Vulkan on the Marshmallow devices that have it.

Android Studio CMake Error: Build Command failed

I'm running into an Error when I open a new project in Android Studio from the Code Samples (Hello JIN). When the Project is opened the following:
Build command failed.
Error while executing process /opt/android-sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/src/main/cpp -B/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a -GAndroid Gradle - Ninja -DANDROID_ABI=arm64-v8a -DANDROID_NDK=/opt/android-sdk/ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/build/intermediates/cmake/arm8/release/obj/arm64-v8a -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/opt/android-sdk/cmake/3.6.4111459/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/opt/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-23 -DANDROID_TOOLCHAIN=clang}
-- Check for working C compiler: /opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- broken
-- Configuring incomplete, errors occurred!
See also "/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeOutput.log".
See also "/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeError.log".
CMake Error at /opt/android-sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler
"/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeTmp
Run Build Command:"/opt/android-sdk/cmake/3.6.4111459/bin/ninja"
"cmTC_0053d"
[1/2] Building C object CMakeFiles/cmTC_0053d.dir/testCCompiler.c.o
FAILED:
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
--target=aarch64-none-linux-android
--gcc-toolchain=/opt/android-sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
--sysroot=/opt/android-sdk/ndk-bundle/sysroot -isystem
/opt/android-sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android
-D__ANDROID_API__=23 -g -DANDROID -ffunction-sections -funwind-tables
-fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat
-Werror=format-security -fPIE -o
CMakeFiles/cmTC_0053d.dir/testCCompiler.c.o -c
/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeTmp/testCCompiler.c
/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang:
error while loading shared libraries: libncurses.so.5: cannot open shared
object file: No such file or directory
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt
This Error drops mutliple times in the IDE
I'm using Arch-Linux 64x
Cmake.txt:
cmake_minimum_required(VERSION 3.4.1)
add_library(hello-jni SHARED
hello-jni.c)
# Include libraries needed for hello-jni lib
target_link_libraries(hello-jni
android
log)
Build -> Refresh Linked C++ Projects resolved this error for me.
I found this Solution Online and this worked, however there was no explanation on how it worked:
Remove the following block of code from you build.gradle file:
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
#rpurohit was nearly right, Clang isn't working properly. But to change the Compiler you need to change build.gradle, in my build.gradle it was Line 12:
apply plugin: 'com.android.application'
1 android {
2 compileSdkVersion 25
3 buildToolsVersion '25.0.2'
4 defaultConfig {
5 applicationId 'com.example.hellojni'
6 minSdkVersion 23
7 targetSdkVersion 25
8 versionCode 1
9 versionName "1.0"
10 externalNativeBuild {
11 cmake {
12 arguments '-DANDROID_TOOLCHAIN=clang' --> gcc
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
productFlavors {
arm7 {
// in the future, ndk.abiFilter might also work
ndk {
abiFilter 'armeabi-v7a'
}
}
arm8 {
ndk {
abiFilters 'arm64-v8a'
}
}
arm {
ndk {
abiFilter 'armeabi'
}
}
x86 {
ndk {
abiFilter 'x86'
}
}
x86_64 {
ndk {
abiFilter 'x86_64'
}
}
mips {
ndk {
abiFilters 'mips', 'mips64'
}
}
universal {
ndk {
abiFilters 'mips', 'mips64', 'x86', 'x86_64'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
}
I would recommend using GCC instead of clang for the time being because clang still does not contain all features. You can change your compiler by doing the following:
set(CMAKE_C_COMPILER /path-to-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc)
However, the darwin-x86_64 directory only exists if you are on a Mac. If you are on another platform, just use the directory that exists under the prebuilt folder.
I encountered this problem because I set the wrong path of native-lib.cpp. After changing
add_library(native-lib SHARED native-lib.cpp)
to
add_library(native-lib SHARED src/main/jni/native-lib.cpp)
it worked again.
By the way, this is part of my project's structure.
CMakeLists.txt
src
|__main
|___jni
|___native-lib.cpp
In case previous answer doesn't work for you, as it happened to me, try to fix permissions in the bin folder of cmake and for ndk. In my case: C:\android-sdk\cmake\3.6.4111459\bin and c:\android-sdk\ndk-bundle
In my case Users group did had no permissions so Android Studio wasn't able to run cmake. Make sure it has Read and execution permissions.
This error sometimes occurs when you upgrade gradle or other dependencies.
a simple solution is Build > "Refresh linked C++ project" and after that rebuilding your project. everything goes right
I tried the solutions provided above but no luck. Then I changed the path of OpenCV_DIR which was set in the CMakeLists.txt file and it worked. My project was not pointing to the right path, which was causing the error. Make sure you have provided the right path in your CMakeLists.txt file.
For example :
set(OpenCV_DIR "...../OpenCV_Android/install/sdk/native/jni/abi-arm64-v8a")
I find this way can work:
not need delete below:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
this is useful .and your project just less the ninja file .
you can fllow this way can build successful!
here is the result:
Make was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
you should install ninja
download ninja here ninja download file
get the ninja file
copy the ninja file to the /usrlocal/bin
build again .the project run successfull!!

Categories

Resources