Hi all,
I am fairly new to android studio and am trying to get to grips with the cradle and CMake features so I can make use of my c++ project source code.
I have found similar questions, however, non of them are related to the new Android Studio 2.2.2 using CMake without the need for Android.mk files, etc...
This code relies on Boost::asio, Boost::thread and Boost::sharedPointers which all depend on the Boost::system library for errors etc. I have managed to get the Boost headers working but am totally stumped after pouring through documentation for a week now and would really appreciate it if anyone could throw some light on this before I loose all my hair...
My development environment is Unix based Mac OS X
The CMakeLists.txt file is as below:
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.
cmake_minimum_required(VERSION 3.4.1)
include_directories(/usr/local/Cellar/jpeg/8d/include)
add_library(tiff_lib SHARED IMPORTED)
set_target_properties(tiff_lib PROPERTIES IMPORTED_LOCATION
/usr/local/Cellar/libtiff/4.0.6/lib/libtiff.a)
include_directories(/usr/local/Cellar/libpng/1.6.21/include)
add_library(png_lib SHARED IMPORTED)
set_target_properties(png_lib PROPERTIES IMPORTED_LOCATION
/usr/local/Cellar/libpng/1.6.21/lib/libpng.a)
include_directories(/usr/local/Cellar/libtiff/4.0.6/include)
add_library(jpeg_lib SHARED IMPORTED)
set_target_properties(jpeg_lib PROPERTIES IMPORTED_LOCATION
/usr/local/Cellar/jpeg/8d/lib/libjpeg.a)
set (BOOST_ROOT "/usr/local/Cellar/boost/1.62.0")
set (Boost_INCLUDE_DIR "/usr/local/Cellar/boost/1.62.0/include")
set (BOOST_LIBRARYDIR "/usr/local/Cellar/boost/1.62.0/lib")
set (Boost_USE_STATIC_LIBS ON)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
find_package(Boost 1.62.0 EXACT COMPONENTS
date_time
filesystem
regex
serialization
system
timer)
include_directories(/Users/robertblack/Desktop/Member_Aandroid_1/app/src/main/cpp/include)
add_subdirectory(src/main/cpp/utilities)
# 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 it 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).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included 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 the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
mathUtilities
stringUtilites
# Links the target library to the log library
# included in the NDK.
${log-lib} )
And the cradle.build file is as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example.robertblack.member_aandroid_1"
minSdkVersion 11
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions -DBOOST_SYSTEM_NO_DEPRECATED"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
testCompile 'junit:junit:4.12'
}
And the errors I am receiving when trying to build are as follows:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing '/Applications/android-sdk-macosx/cmake/3.6.3155560/bin/cmake' with arguments {--build /Users/robertblack/Desktop/Member_Aandroid_1/app/.externalNativeBuild/cmake/debug/mips64 --target workerThreadImp}
[1/2] Building CXX object src/main/cpp/utilities/Assets/CMakeFiles/workerThreadImp.dir/WorkerThreadImp.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/mips64/libworkerThreadImp.so
FAILED: : && /Applications/android-sdk-macosx/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -target mips64el-none-linux-android -gcc-toolchain /Applications/android-sdk-macosx/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64 --sysroot=/Applications/android-sdk-macosx/ndk-bundle/platforms/android-21/arch-mips64 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -std=c++11 -frtti -fexceptions -DBOOST_SYSTEM_NO_DEPRECATED -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libworkerThreadImp.so -o ../../../../build/intermediates/cmake/debug/obj/mips64/libworkerThreadImp.so src/main/cpp/utilities/Assets/CMakeFiles/workerThreadImp.dir/WorkerThreadImp.cpp.o -lm "/Applications/android-sdk-macosx/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips64/libgnustl_static.a" && :
src/main/cpp/utilities/Assets/CMakeFiles/workerThreadImp.dir/WorkerThreadImp.cpp.o: In function `boost::asio::error::get_system_category()':
/usr/local/Cellar/boost/1.62.0/include/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Thank you for your time to look at this and I look forward to you replies.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e643cc44-bd8a-42a7-8ccf-13c07569cfcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kenneth Geisshirt, M.Sc., Ph.D.
Majbøl Allé 18, DK-2770 Kastrup, +45 60 62 71 82
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7c25bb91-00d5-45cb-bd4e-91a3b26aeef9%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7c25bb91-00d5-45cb-bd4e-91a3b26aeef9%40googlegroups.com.
I am new to android studio. I created a simple project and run it. I am getting the below issue.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/4812fab9-007d-42da-acf8-0d711f197621%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.