• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

android JNI how to convert a CMAKE file to a JNI Android.mk with supporting files

April 11, 2020 by

Questions › android JNI how to convert a CMAKE file to a JNI Android.mk with supporting files
0
Vote Up
Vote Down
Garmaine asked 4 years ago

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
Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: android, c++, cmake, java, java-native-interface

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023