So I'm trying to write my first native library to reuse my C++ code in Android and iOS but just cannot get it to run under Android Studio 2.3
I followed the instructions to the letter (I hope) which mostly consist of:
Write a CMakeLists.txt file containing (in my case):
cmake_minimum_required(VERSION 3.4.1)
add_library(
test-lib
STATIC
src/main/cpp/test.cpp
src/main/cpp/cpp_wrapper.cpp)
include_directories(src/main/cpp/include/)
find_library(
log-lib
log )
target_link_libraries(test-lib ${log-lib} )
add_library( app-glue
STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c )
target_link_libraries( test-lib app-glue ${log-lib} )
Then link the CMake file to gradle in your modules build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId 'com.mysample.id'
minSdkVersion 19
targetSdkVersion 25
versionCode 9
versionName "1.3.0"
}
buildTypes {
release { ... }
}
productFlavors {
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
repositories {
maven { ... }
}
dependencies { ... }
That should be sufficient. Sadly its not. I just can't figure out what I'm missing here. Once (and really only once) I actually got an error message from CMake because of an intentionally placed typo in the cpp file, but that was the only thing I ever saw from it. No library *.so file is created, and of course none is packaged with the apk, so the app crashes as soon as it tries to load it.
Update: I was looking in the wrong place, there actually are some files from CMake in app/.externalNativeBuild/cmake which reflect build configurations and cpu architectures and they even include an test-lib.dir
directory, but this is empty. I looked through the files to see if there is some clue but couldn't find anything interesting.
Any suggestions welcome!