I have a working Cmake android project and I am moving it to a new application where I cannot use Cmake. I need to convert it to use the Android JNI / Android.mk & Application.mk.. However I am having issues with the 2 directories of support files. One has namespace jni, the other appears to be mostly headers. Unfortunately the conversion does not seem as straight forward as the docs suggest.
The file structure is
src/main/cpp
deps/otherlib/include
deps/jni/include
Android.mk
Application.mk
main.cpp logger.h
foobar_handler.cpp
foobar_handler.hpp
foo_test.hpp
foo_test.cpp
When I try to sync the files, all the library files under deps/jni/include show unresolved references to anything in angle brackets. IE #include
Its been a while since I have done anything with C++. I notice that the jni cpp files all have namespace jni
I think I am missing a step for it to work in my Android.mk. The CMAKE compiles fine, but I cannot use it. I tried adding it to LOCAL_EXPORT_C_INCLUDES with no success.
Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native_crash_handler
LOCAL_SRC_FILES := \
main.cpp logger.h \
foobar_handler.cpp \
foobar_handler.hpp \
foo_test.hpp \
foo_test.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS := -fexceptions -fno-omit-frame-pointer
LOCAL_CFLAGS += -Wall -Werror
CXX11_FLAGS := -std=gnu++11
LOCAL_CFLAGS += $(CXX11_FLAGS)
LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS)
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
CMakelists.txt
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
# 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 them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
foobar_handler
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
main.cpp
logger.h
foobar_handler.cpp
foobar_handler.hpp
foo_test.hpp
foo_test.cpp
)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries 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 this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
foobar_handler
# Links the target library to the log library
# included in the NDK.
${log-lib}
)
target_include_directories(
foobar_handler PRIVATE
deps/otherlib/include
deps/jni/include
)
Application.mk
APP_STL := c++_shared
APP_CFLAGS += -DASIO_STANDALONE
APP_CPPFLAGS += -std=c++14 -fexceptions -frtti
APP_LDFLAGS += -llog -lgcov --coverage
Please login or Register to submit your answer