I try to compile a shared library on Ubuntu using CMake for Android
my "toolchain.cmake" file :
set (CMAKE_SYSTEM_NAME Android)
set (CMAKE_SYSTEM_VERSION 26)
set (CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set (CMAKE_ANDROID_NDK "/home/user/android-ndk-r23b")
set (CMAKE_ANDROID_STL_TYPE c++_shared)
but I have this message error :
Android: The API specified by CMAKE_SYSTEM_VERSION='26' does not exist in the NDK. The directory: /home/user/android-ndk-r23b/platforms/android-26 does not exist.
Thanks
According to your error message it seems that the path /home/user/android-ndk-r23b/platforms/android-26 does not exist. You can download the NDK from here https://developer.android.com/ndk/downloads and create and validate the path /home/user/android-ndk-r23b/platforms/android-26 from hand.
I just switched from NDK 15 to the one installed with Android Studio (which is currently 17). But now malloc and friends is not found, even though stdlib.h is included.
I've looked everywhere, but found no solution so far. My base class is in c++, which uses a C library. I think this might be relevant. below is the console output.
In file included from ../../../../../../../hdm-deepmap-sql/dms/hdm-deepmap-sql/include/dms/DeepMapSQL.hpp:13:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/string:470:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/string_view:169:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/__string:56:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/algorithm:643:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:644:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/typeinfo:61:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/exception:82:
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:125:9: error: no member named 'calloc' in the global namespace
using ::calloc;
~~^
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:126:9: error: no member named 'free' in the global namespace
using ::free;
~~^
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:127:9: error: no member named 'malloc' in the global namespace
using ::malloc;
~~^
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:128:9: error: no member named 'realloc' in the global namespace
using ::realloc;
~~^
4 errors generated.
ninja: build stopped: subcommand failed.
In addition, this is the CMake file for the library:
cmake_minimum_required(VERSION 3.6)
include(../../toolchain/macros.cmake)
project(hdmsql)
set(HDM_SQL_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dms/hdm-deepmap-sql)
file(GLOB_RECURSE SOURCES
${HDM_SQL_SRC_DIR}/*.c
${HDM_SQL_SRC_DIR}/*.cpp
)
list(REMOVE_ITEM SOURCES ${HDM_SQL_SRC_DIR}/src/treeview.c)
add_library(hdmsql STATIC
${SOURCES}
)
target_link_libraries(hdmsql hdmmaputils)
target_include_directories(hdmsql PUBLIC ${HDM_SQL_SRC_DIR}/include/dms/)
target_include_directories(hdmsql PRIVATE ${HDM_SQL_SRC_DIR}/src/)
#############
configure_file(${HDM_SQL_SRC_DIR}/include/dms/DeepMapSQL.hpp "${CMAKE_CURRENT_BINARY_DIR}/DeepMapSQL.hpp")
configure_file(${HDM_SQL_SRC_DIR}/include/dms/dms.h "${CMAKE_CURRENT_BINARY_DIR}/dms.h")
configure_file(${HDM_SQL_SRC_DIR}/include/dms/geometry.h "${CMAKE_CURRENT_BINARY_DIR}/geometry.h")
configure_file(${HDM_SQL_SRC_DIR}/include/dms/vdbeapi.h "${CMAKE_CURRENT_BINARY_DIR}/vdbeapi.h")
I found a workaround. There was a malloc.h header which wrapped malloc calls for the various targeted platforms. Besides that debatably naming a header malloc.h should be considered bad practice, the issue really seems to be in recent versions of the NDK, because the header is included as a private header in CMake and should not collide with the system malloc.h.
Renaming the header solved the issue.
How do I compile and use Boost for the Android NDK? I've tried everything I've found online, from Boost for Android to compiling it myself with the bjam file. However, I do not succeed. When I try compiling it with bjam, I get the following error:
error: toolset gcc initialization:
error: version 'androidR10e' requested but 'g++-androidR10e' not found and version '4.2.1' of default 'g++' does not match
error: initialized from /path/to/android-ndk-r10e/sources/boost/tools/build/v2/user-config.jam:86
Has anyone successfully used Boost with Android NDK R10e?
And when I can compile it, how should I do to use it in my Android app project?
We managed to compile it for NDKr10d. It should be the same for NDKr10e.
The project-config.bjam should point to the gcc compiler from the NDK. Ours looks like this :
import option ;
using gcc : arm : D:\\android\\ndk\\toolchains\\arm-linux-androideabi-4.9\\prebuilt\\windows-x86_64\\bin\\arm-linux-androideabi-g++.exe ;
option.set keep-going : false ;
Then just compile with b2, telling paths to android includes :
b2 --reconfigure <your options>
toolset=gcc-arm
include=<ndk folder>\sources\cxx-stl\gnu-libstdc++\4.9\include
include=<ndk folder>\sources\cxx-stl\gnu-libstdc++\4.9\libs\<target platform>\include
include=<ndk folder>\platforms\<android api version>\arch-arm\usr\include
install --libdir=stage\lib\<target platform>
We're about to move to ndkr10e. Could you tell if boost still works with it ? :)
The simplest way would be to use CrystaX NDK, which contains already built and ready-to-use Boost libraries. And here are examples how to use Boost with CrystaX NDK: 1, 2
Following the boost directions, I was able to build boost 1.60 with NDKr10e on Ubuntu 12.04 (although I suspect very little depends on the host system). Here are my notes:
get and unpack boost source tarball (i used 1.60): boost_1_60_0.tar.bz2
moskewcz#maaya:/scratch/moskewcz/android/src$ ll
total 74M
drwx------ 10 moskewcz moskewcz 4.0K Mar 9 14:14 boost_1_60_0
-rw-rw-r-- 1 moskewcz moskewcz 74M Jan 5 11:15 boost_1_60_0.tar.bz2
follow boost instructions in getting started on unix "Build Custom Binaries" section
use a fresh, empty root to install b2 i.e. /scratch/boost-build-root; use usr as prefix; again following the boost instructions:
moskewcz#maaya:/scratch/moskewcz/android/src/boost_1_60_0/tools/build$ ./bootstrap.sh
moskewcz#maaya:/scratch/moskewcz/android/src/boost_1_60_0/tools/build$ ./b2 install --prefix=/scratch/moskewcz/android/boost-build-root/usr
put b2 in path (again as per instructions)
export PATH=/scratch/moskewcz/android/boost-build-root/usr/bin:$PATH
in some jamfile (i had no ~/user-config.jam, so i created one and used that, maybe there's a better choice of jamfile to create/edit) add some jam-code (?) to define a gcc version (toolset) pointing to a g++ from a standalone toolchain. note that this is a toolchain created with the NDK in the normal fashion following its 'create a standalone toolchain' directions. i am NOT pointing to a g++ inside the NDK itself (that may or may not work, i dunno):
import option ;
using gcc : arm_linux_android_4.9 : /scratch/android-stc/bin/aarch64-linux-android-g++ ;
option.set keep-going : false ;
go to boost project root and build, mostly as per directions. --build-dir may be optional? also added -j8 to do || build
moskewcz#maaya:/scratch/moskewcz/android/src/boost_1_60_0$ b2 -j8 --build-dir=bin.v2 toolset=gcc-arm_linux_android_4.9 stage
note that this tries to build both static and shared libs by default, but building shared libs fails due to android not having librt.so -- according to my research, people claim that under android (some of?) the functionality of librt.so is inside libc.so -- so it may be okay to simply remove -lrt from the linking steps in order to build shared libs for android. i did not attempt this. see:
https://code.google.com/p/android/issues/detail?id=5730
Building Boost for Android with error "cannot find -lrt"
I only managed to build with 10d. Cross compiling Linux->Android using Boost for Android worked straight away with that.
To download a slightly outdated ndk, as not all ndk are immediately supported by Boost for Android, you can use this guide: Where do I find old versions of Android NDK?
Note: I also wanted to specify the toolchain. I had to do it in 2 places:
In build-android.sh, just after the line mentioned here above:
TOOLCHAIN=${TOOLCHAIN:-arm-linux-androideabi-4.9}
In the command line
bash build-android.sh [ndk location] --toolchain=arm-linux-androideabi-4.9
In fact, it worked better when I specified exactly which boost components I wanted with --with-libraries=[comma separated list].
If instead I would build everything, I would get:
...failed updating 38 targets...
...skipped 6 targets...
...updated 10568 targets...
ERROR: Failed to build boost for android!
Done!
Here: http://silverglint.com/boost-for-android/ you can find a simple and painless new way to build a modern (eg 1.64.0) version of boost for android.
Works with clang and gcc.
Also included is a sample app that shows you how to use the boost binaries thus built.
I am facing the following issue when trying to compile a c program using openssl for android x-86. I set up the environment variables as follows using the following script:
setenv-android.sh
After running the script I have the following environment.
./setenv-android_x86.sh
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
Error: FIPS_SIG does not specify incore module. Please edit this script.
ANDROID_NDK_ROOT: /opt/android-ndk-r9d-x86
ANDROID_ARCH: arch-x86
ANDROID_EABI: x86-4.6
ANDROID_API: android-18
ANDROID_SYSROOT: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86
ANDROID_TOOLCHAIN: /opt/android-ndk-r9d-x86/toolchains/x86-4.6/prebuilt/darwin-x86_64/bin
FIPS_SIG:
CROSS_COMPILE: i686-linux-android-
ANDROID_DEV: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86/usr
However when trying to compile with the following command I get the following error:
pwd
/opt/android-ndk-r9d-x86/bin
./i686-linux-android-gcc Test.c -o test -lcrypto
fatal error: openssl/conf.h: No such file or directory
When I locate for the openssl/conf.h I see the file is available in many places:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/openssl/conf.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/openssl/conf.h
/data/local/arm/ssl/include/openssl/conf.h
/data/local/ssl/include/openssl/conf.h
/openssl/include/openssl/conf.h
/openssl-1.0.1e/include/openssl/conf.h
/openssl-1.0.1g/include/openssl/conf.h
/opt/local/include/openssl/conf.h
/usr/include/openssl/conf.h
/usr/local/include/openssl/conf.h
/usr/local/ssl/android-14/include/openssl/conf.h
/usr/local/ssl/android-18/include/openssl/conf.h
/usr/local/ssl/android-18-x86/include/openssl/conf.h
/usr/local/ssl/include/openssl/conf.h
I think the proper path is this:
/usr/local/ssl/android-18-x86/include/openssl/conf.h
I tried with the -L option but with no luck.
-L/usr/local/ssl/android-18-x86/include/
Can anybody please explain how to setup the path properly to solve this issue. (finally there is no issue with the C code as it compiles properly with gcc)
You are compiling your code using the Android NDK, which creates a "virtual" compiling environment by placing everything you need to compile for android into the ${ANDROID_SYSROOT} directory.
Those directories you listed are outside that sysroot, and therefore are not available to the build system, hence the errors. You must install OpenSSL for Android and putting the resulting headers and binaries there. You might follow this guide to assist you in that.
I have to edit a project using some C++ stuff (commons-codec-1.4) to read a SVG file. If I comment out the SVG reference it works fine but I have to run with it. It originally compiled with NDK. I downloaded NDK but don't know how to attach with this project.
build.log file in jni folder says
Android NDK: WARNING: Unsupported source file extensions in /cygdrive/c/work/Android/Source/yprintit-android/jni/Android.mk for module svgandroid
Android NDK: libpng/png.h libpng/pngconf.h libpng/pngpriv.h libsvg/svg.h libsvg/svgint.h libsvg/svg_ascii.h libsvg/svg_version.h libsvg/svg_hash.h libsvg-android/svg-android.h libsvg-android/svg-android-internal.h
Compile thumb : svgandroid <= /cygdrive/c/work/Android/Source/yprintit-android/jni/datauri/base64.c
SharedLibrary : libsvgandroid.so
Install : libsvgandroid.so => /cygdrive/c/work/Android/Source/yprintit-android/libs/armeabi