I want to use c++ in my flutter project . To do this I first need to convert my c++ file into a shared library or into a .so file according to android environment. To do so I am using this command:-
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -G Ninja -DANDROID_NDK=$ANDROID_NDK -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-30 -Sandroid -Bbin/android/arm64-v8a
But it is continueously showing me this error:-
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -G Ninja -DANDROID_NDK=$ANDROID_NDK -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=
android-30 -Sandroid -Bbin/android/arm64-v8a
CMake Warning:
Ignoring extra path from command line:
"F:/dart ffi/ffiproject/.toolchain.cmake"
CMake Warning at C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android-legacy.toolchain.cmake:51 (message):
Using custom NDK path (ANDROID_NDK is set): F:/dart
ffi/ffiproject/android/$ANDROID_NDK
Call Stack (most recent call first):
C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android.toolchain.cmake:54 (include)
F:/dart ffi/ffiproject/bin/android/arm64-v8a/CMakeFiles/3.24.1/CMakeSystem.cmake:6 (include)
CMakeLists.txt:5 (project)
CMake Error at C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android-legacy.toolchain.cmake:64 (file):
file failed to open for reading (No such file or directory):
F:/dart ffi/ffiproject/android/$ANDROID_NDK/source.properties
Call Stack (most recent call first):
C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android.toolchain.cmake:54 (include)
F:/dart ffi/ffiproject/bin/android/arm64-v8a/CMakeFiles/3.24.1/CMakeSystem.cmake:6 (include)
CMakeLists.txt:5 (project)
CMake Error at C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android-legacy.toolchain.cmake:69 (message):
Failed to parse Android NDK revision: F:/dart
ffi/ffiproject/android/$ANDROID_NDK/source.properties.
Call Stack (most recent call first):
C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android.toolchain.cmake:54 (include)
F:/dart ffi/ffiproject/bin/android/arm64-v8a/CMakeFiles/3.24.1/CMakeSystem.cmake:6 (include)
CMakeLists.txt:5 (project)
CMake Error at C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android-legacy.toolchain.cmake:175 (include):
include could not find requested file:
F:/dart ffi/ffiproject/android/$ANDROID_NDK/build/cmake/platforms.cmake
Call Stack (most recent call first):
C:/Users/super/AppData/Local/Android/Sdk/ndk/25.1.8937393/build/cmake/android.toolchain.cmake:54 (include)
F:/dart ffi/ffiproject/bin/android/arm64-v8a/CMakeFiles/3.24.1/CMakeSystem.cmake:6 (include)
CMakeLists.txt:5 (project)
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:5 (project):
The CMAKE_C_COMPILER:
F:/dart ffi/ffiproject/android/$ANDROID_NDK/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:5 (project):
The CMAKE_CXX_COMPILER:
F:/dart ffi/ffiproject/android/$ANDROID_NDK/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "F:/dart ffi/ffiproject/bin/android/arm64-v8a/CMakeFiles/CMakeOutput.log".
See also "F:/dart ffi/ffiproject/bin/android/arm64-v8a/CMakeFiles/CMakeError.log".
I dont know how to solve it.
Here is my CMakeLists.txt file:-
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_MAKE_PROGRAM "C:/src/ninja-win/ninja.exe" CACHE FILEPATH "" FORCE)
set( CMAKE_CXX_COMPILER g++ )
set( CMAKE_C_COMPILER gcc )
project(ffiproject)
add_library(
lib
SHARED
lib.cpp
)
find_library(
lib
log
)
target_link_libraries(
lib
${log_lib}
)
Please Help Me
Related
I am creating an Android library that uses OpenCV via NDK. It doesn't require any Java parts of OpenCV, native parts only, so I decided not to use OpenCV for Android to reduce the size of the OpenCV code the library needs.
Now I need to download and build the native (C++) part of OpenCV using CMake so that the library won't require its users to download and install OpenCV on their own.
Currently my module's build.gradle contains this:
externalNativeBuild {
cmake {
cppFlags '-std=c++11 -frtti -fexceptions'
arguments '-DANDROID_ARM_NEON=TRUE'
}
}
And my CMakeLists.txt is:
cmake_minimum_required(VERSION 3.18.1)
project("mylib")
set(OPENCV_INSTALL_DIR ${CMAKE_BINARY_DIR}/opencv-install)
include(ExternalProject)
ExternalProject_Add(opencv
GIT_REPOSITORY https://github.com/opencv/opencv.git
GIT_TAG 4.5.5
UPDATE_DISCONNECTED TRUE
CMAKE_ARGS
<OpenCV arguments I need>
-DCMAKE_INSTALL_PREFIX=${OPENCV_INSTALL_DIR}
)
include_directories(${OPENCV_INSTALL_DIR}/include)
link_directories(${OPENCV_INSTALL_DIR}/lib)
set(OPENCV_LIBRARIES <OpenCV modules I use>)
add_library(mylib SHARED mylib.cpp)
add_dependencies(mylib opencv)
find_library(log-lib log)
target_link_libraries(mylib ${log-lib} ${OPENCV_LIBRARIES})
I am using Android Studio. When I try to build the library, the downloading process goes fine, but at the configure step I get the following error:
FAILED: opencv-prefix/src/opencv-stamp/opencv-configure
cmd.exe /C "cd /D <my lib module path>\.cxx\Debug\612145b5\x86_64\opencv-prefix\src\opencv-build && <my Android SDK path>\cmake\3.18.1\bin\cmake.exe -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_opencv_apps=OFF -DBUILD_JAVA=OFF -DBUILD_FAT_JAVA_LIB=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DWITH_GTK=OFF -DWITH_WIN32UI=OFF -DWITH_FFMPEG=OFF -DWITH_V4L=OFF -DCPU_BASELINE=NEON -DCMAKE_INSTALL_PREFIX=<my lib module path>/.cxx/Debug/612145b5/x86_64/opencv-install -GNinja <my lib module path>/.cxx/Debug/612145b5/x86_64/opencv-prefix/src/opencv && <my Android SDK path>\cmake\3.18.1\bin\cmake.exe -E touch <my lib module path>/.cxx/Debug/612145b5/x86_64/opencv-prefix/src/opencv-stamp/opencv-configure"
CMake Error: CMake 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.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
As I see, CMake cannot find the following components:
Ninja
C++ compiler
C compiler
I can get rid of the first error, if I add ninja's path from NDK to the PATH variable, I don't think thats how it should be done though. Neither do I want to pass CMAKE_CXX_COMPILER and CMAKE_C_COMPILER to CMake manually, as it seems like it should be done automatically by Android Studio.
So, how can I fix this?
I want to build caffe2 on macOS.
build caffe2 is every thing OK, but when I build android, use caffe2/scripts/build_android.sh the processing is to 100% and then occurred:
CMake Error at /usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CheckCXXSourceCompiles.cmake:97 (try_compile):
Failed to configure test project build system.
Call Stack (most recent call first):
cmake/MiscCheck.cmake:34 (CHECK_CXX_SOURCE_COMPILES)
CMakeLists.txt:61 (include)
my cmake version is :
cmake version 3.10.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
the all log is :
```
CMake Error at third_party/android-cmake/android.toolchain.cmake:310 (file):
file STRINGS file
"/Users/zhouhuacong/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/usr/include/android/api-level.h"
cannot be read.
Call Stack (most recent call first):
third_party/android-cmake/android.toolchain.cmake:814 (__DETECT_NATIVE_API_LEVEL)
/usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeDetermineSystem.cmake:94 (include)
CMakeLists.txt:6 (project)
CMake Error at third_party/android-cmake/android.toolchain.cmake:816 (message):
Specified Android API level (21) does not match to the level found ().
Probably your copy of NDK is broken.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeDetermineSystem.cmake:94 (include)
CMakeLists.txt:6 (project)
CMake Deprecation Warning at /usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeForceCompiler.cmake:69 (message):
The CMAKE_FORCE_C_COMPILER macro is deprecated. Instead just set
CMAKE_C_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
third_party/android-cmake/android.toolchain.cmake:1139 (CMAKE_FORCE_C_COMPILER)
/usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeDetermineSystem.cmake:94 (include)
CMakeLists.txt:6 (project)
CMake Deprecation Warning at /usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeForceCompiler.cmake:83 (message):
The CMAKE_FORCE_CXX_COMPILER macro is deprecated. Instead just set
CMAKE_CXX_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
third_party/android-cmake/android.toolchain.cmake:1151 (CMAKE_FORCE_CXX_COMPILER)
/usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeDetermineSystem.cmake:94 (include)
CMakeLists.txt:6 (project)
-- Performing Test CAFFE2_LONG_IS_INT32_OR_64
CMake Error at /Users/zhouhuacong/CaffeProject/caffe2/third_party/android-cmake/android.toolchain.cmake:310 (file):
file STRINGS file
"/Users/zhouhuacong/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/usr/include/android/api-level.h"
cannot be read.
Call Stack (most recent call first):
/Users/zhouhuacong/CaffeProject/caffe2/third_party/android-cmake/android.toolchain.cmake:814 (__DETECT_NATIVE_API_LEVEL)
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/3.10.1/CMakeSystem.cmake:6 (include)
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)
CMake Error at /Users/zhouhuacong/CaffeProject/caffe2/third_party/android-cmake/android.toolchain.cmake:816 (message):
Specified Android API level (21) does not match to the level found ().
Probably your copy of NDK is broken.
Call Stack (most recent call first):
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/3.10.1/CMakeSystem.cmake:6 (include)
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)
CMake Deprecation Warning at /usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeForceCompiler.cmake:69 (message):
The CMAKE_FORCE_C_COMPILER macro is deprecated. Instead just set
CMAKE_C_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
/Users/zhouhuacong/CaffeProject/caffe2/third_party/android-cmake/android.toolchain.cmake:1139 (CMAKE_FORCE_C_COMPILER)
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/3.10.1/CMakeSystem.cmake:6 (include)
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)
CMake Deprecation Warning at /usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CMakeForceCompiler.cmake:83 (message):
The CMAKE_FORCE_CXX_COMPILER macro is deprecated. Instead just set
CMAKE_CXX_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
/Users/zhouhuacong/CaffeProject/caffe2/third_party/android-cmake/android.toolchain.cmake:1151 (CMAKE_FORCE_CXX_COMPILER)
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/3.10.1/CMakeSystem.cmake:6 (include)
/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)
CMake Error at /usr/local/Cellar/cmake/3.10.1/share/cmake/Modules/CheckCXXSourceCompiles.cmake:97 (try_compile):
Failed to configure test project build system.
Call Stack (most recent call first):
cmake/MiscCheck.cmake:34 (CHECK_CXX_SOURCE_COMPILES)
CMakeLists.txt:61 (include)
-- Configuring incomplete, errors occurred!
See also "/Users/zhouhuacong/CaffeProject/caffe2/build_android/CMakeFiles/CMakeOutput.log".
```
I find the first error file STRINGS file
"/Users/zhouhuacong/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/usr/include/android/api-level.h"
cannot be read.
but i don't find the include folder in my mac. there are only /Users/zhouhuacong/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/usr/lib folder.
Is this my NDK environment problem? I use the Android Studio 3.0, and download NDK 16.
Where am I wrong?
I tried to create simple android application with NDK support. I followed https://developer.android.com/studio/projects/add-native-code.html#new-project while creating project. After creating project it gives me following error:
External Native Build Issues
Build command failed.
Error while executing 'C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {-HD:\AndroidNDKExample\app -BD:\AndroidNDKExample\app\.externalNativeBuild\cmake\release\armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\AndroidNDKExample\app\build\intermediates\cmake\release\obj\armeabi -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\cmake\3.6.3155560\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=19 -DCMAKE_CXX_FLAGS=-frtti -fexceptions}
-- Configuring incomplete, errors occurred!
CMake Error at C:/Users/Nilesh.Kashid/AppData/Local/Android/sdk/cmake/3.6.3155560/android.toolchain.cmake:351 (message):
Failed to parse Android NDK revision:
C:/Users/Nilesh.Kashid/AppData/Local/Android/Sdk/ndk-bundle/source.properties.
Call Stack (most recent call first):
C:/Users/Nilesh.Kashid/AppData/Local/Android/sdk/cmake/3.6.3155560/share/cmake-3.6/Modules/CMakeDetermineSystem.cmake:98 (include)
CMakeLists.txt
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Error:executing external native build for cmake D:\AndroidNDKExample\app\CMakeLists.txt
Build command failed.
Error while executing 'C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {-HD:\AndroidNDKExample\app -BD:\AndroidNDKExample\app\.externalNativeBuild\cmake\debug\armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\AndroidNDKExample\app\build\intermediates\cmake\debug\obj\armeabi -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Users\Nilesh.Kashid\AppData\Local\Android\Sdk\cmake\3.6.3155560\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=19 -DCMAKE_CXX_FLAGS=-frtti -fexceptions}
-- Configuring incomplete, errors occurred!
CMake Error at C:/Users/Nilesh.Kashid/AppData/Local/Android/sdk/cmake/3.6.3155560/android.toolchain.cmake:351 (message):
Failed to parse Android NDK revision:
C:/Users/Nilesh.Kashid/AppData/Local/Android/Sdk/ndk-bundle/source.properties.
Call Stack (most recent call first):
C:/Users/Nilesh.Kashid/AppData/Local/Android/sdk/cmake/3.6.3155560/share/cmake-3.6/Modules/CMakeDetermineSystem.cmake:98 (include)
CMakeLists.txt
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Error:executing external native build for cmake D:\AndroidNDKExample\app\CMakeLists.txt
I have downloaded CMake and LLDB android I am using Android Studio 2.2.3 version.
I had the same problem. This problem occurs in older versions of ndk.
Failed to parse Android NDK revision:
The problem was resolved after updating ndk.
The current ndk version is 13.1.3345770.
Reference :
https://developer.android.com/ndk/guides/index.html
I have followed the instructions in this link: http://www.vtk.org/Wiki/VES/Developers_Guide
I have downloaded VES, Andoid ndk-r8b, Android Studio (which has Android sdk), adb, ant.
And following the instructions:
export ANDROID_NDK=/home/ahrgm/Downloads/android-ndk-r8b
cmake -P configure.cmake
cd build
make -j4
the following error appears:
loading initial cache file
/home/ahrgm/VES/CMake/toolchains/TryRunResults.cmake CMake Error at
/home/ahrgm/VES/CMake/toolchains/android.toolchain.cmake:745
(message): Could not find any working toolchain in the NDK.
Probably your Android NDK is broken. Call Stack (most recent call
first): /usr/share/cmake-2.8/Modules/CMakeDetermineSystem.cmake:93
(include) CMakeLists.txt:3 (project)
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly. Missing variable is:
CMAKE_C_COMPILER_ENV_VAR CMake Error: Error required internal CMake
variable not set, cmake may be not be built correctly. Missing
variable is: CMAKE_C_COMPILER CMake Error: Could not find cmake module
file:
/home/ahrgm/VES/Apps/Android/CMakeBuild/build/CMakeExternals/Build/vtk-android/CMakeFiles/2.8.12.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly. Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR CMake Error: Error required internal CMake
variable not set, cmake may be not be built correctly. Missing
variable is: CMAKE_CXX_COMPILER CMake Error: Could not find cmake
module file:
/home/ahrgm/VES/Apps/Android/CMakeBuild/build/CMakeExternals/Build/vtk-android/CMakeFiles/2.8.12.2/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake
Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred! make[2]: * [CMakeExternals/Stamp/vtk-android/vtk-android-configure] Error 1
make[1]: * [CMakeFiles/vtk-android.dir/all] Error 2 make: *** [all]
Error 2
How can I solve this problem?
I managed to build OpenCV 2.4.9 for java following the online instructions.
However I am unable to build for Android
I am using OSX Yosemite, CMake 3.0.2, OpenCV 2.4.9.
The output I get is the following:
platforms [2.4.9] % sh ./scripts/cmake_android_arm.sh CMake Error at platforms/android/android.toolchain.cmake:827 (list): list index: 17 out of range (-17, 16) Call Stack (most recent call first): platforms/build_android_arm/CMakeFiles/3.0.2/CMakeSystem.cmake:6 (include) CMakeLists.txt:56 (project)
-- Detected version of GNU GCC: 49 (409) -- Performing Test HAVE_CXX_WERROR_ADDRESS CMake Error at /Users/mam/Source/opencv/platforms/android/android.toolchain.cmake:711 (list): list sub-command REMOVE_DUPLICATES requires list to be present. Call Stack (most recent call first): /Users/mam/Source/opencv/platforms/build_android_arm/CMakeFiles/3.0.2/CMakeSystem.cmake:6 (include) CMakeLists.txt:2 (project)
CMake Error at /Users/mam/Source/opencv/platforms/android/android.toolchain.cmake:712 (list): list sub-command SORT requires list to be present. Call Stack (most recent call first): /Users/mam/Source/opencv/platforms/build_android_arm/CMakeFiles/3.0.2/CMakeSystem.cmake:6 (include) CMakeLists.txt:2 (project)
CMake Error at /Users/mam/Source/opencv/platforms/android/android.toolchain.cmake:718 (message): No one of known Android ABIs is supported by this cmake toolchain. Call Stack (most recent call first): /Users/mam/Source/opencv/platforms/build_android_arm/CMakeFiles/3.0.2/CMakeSystem.cmake:6 (include) CMakeLists.txt:2 (project)
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage CMake Error: Internal CMake error, TryCompile configure of cmake failed -- Configuring incomplete, errors occurred! See also "/Users/mam/Source/opencv/platforms/build_android_arm/CMakeFiles/CMakeOutput.log".
I tried setting both:
export ANDROID_NDK=~/android-ndk-r8e
and
export ANDROID_STANDALONE_TOOLCHAIN=~/android-toolchain
but both give same error. Any clues to what is causing this? Bad version of CMake?