I've been attempting to build and debug an external Java/C++ source library inside Android Studio 2.2 but I am unable to figure out how to do this or if it is possible.
In specific, I am attempting to use the https://github.com/mapbox/mapbox-gl-native library, but I suspect the solution may be similar for any Java/C++ library. In this case the library contains a Makefile and a CMakeLists.txt file.
I have not seen how the CMakeLists.txt is used, but I have built the Mapbox library from source using the command:
BUILDTYPE=Debug make android
I have created a project using the Android Studio wizard and chose the C++ option which creates a sample .cpp that successfully builds and debugs:
// native-lib.cpp
#include <jni.h>
#include <string>
extern "C"
jstring
Java_com_example_kea_mapboxtest_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
It also create an app/CMakeLists.txt file.
I am looking for anyway I can build and debug a 3rd party C++ source library. My best guess is that there is some way to modify the app/CMakeLists.txt file generated by the wizard to do this, but I'm guessing this is what to do and I can't figure out how.
The reason I think this might be the correct road to take is that the wizard generated app/CMakeLists.txt contains:
# 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
which seems to work. I was thinking it might be possible to reference the library CMakeLists.txt or the Makefile found in the Mapbox source inside the wizard generated CMakeLists.txt. The hope is the library it builds will be debuggable. Alternatively having it statically linked would also be acceptable, so long as I could debug into the C++ source in the library.
Thanks.