Android ndk nested modules

I have a native project that in frustration with the make system I got working by simply jamming all the code together many years ago. I attempted to port the project properly to gradle-experimental, but that’s still a disaster 2.5 years later. I’m now trying to get the system to work within the reorganized (for gradle-experimental) project.

Here’s the organization:

  • transformClassesAndResourcesWithProguardForRelease FAILED
  • Android Google Maps get Boundary Co-ordinates
  • Error: Non-static method 'findViewById(int)' cannot be referenced from a static context
  • Android ActionbarSherlock SearchView
  • PACKAGE_REMOVED & then PACKAGE_ADDED are fired along with PACKAGE_REPLACED Intent Action
  • Why does AOSP add new APIs to support libraries without adding them to SDK?
    • jpeg (full native)
    • processor (full native, dependent on jpeg)
    • library (jni, dependent on processor and jpeg)

    -jni (contains,
    ----jni (and source co-located)
    -----jni (and source co-located)

    I know I could flatten this if I use the make files, but I figure someday in 2020 Android Studio will truly support native so I figured I’d keep the current project format.

    Here are my make files:


    LOCAL_PATH := $(call my-dir)
    include $(STARTUP_DIR)/../jpeg/src/main/jni/
    include $(STARTUP_DIR)/../processor/src/main/jni/
    include $(STARTUP_DIR)/../library/src/main/jni/
    include $(CLEAR_VARS)


    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_ARM_MODE := arm
    LOCAL_SRC_FILES := [truncated]
    LOCAL_CFLAGS += -O3 -fstrict-aliasing -fprefetch-loop-arrays
    #LOCAL_CFLAGS += -march=armv6j
    # enable tile based decode
    ifeq ($(TARGET_ARCH_VARIANT),x86-atom)
      LOCAL_SRC_FILES += jidctintelsse.c
    # enable armv6 idct assembly
    ifeq ($(strip $(TARGET_ARCH)),arm)
    # use mips assembler IDCT implementation if MIPS DSP-ASE is present
    ifeq ($(strip $(TARGET_ARCH)),mips)
      ifeq ($(strip $(ARCH_MIPS_HAS_DSP)),true)
      LOCAL_SRC_FILES += \
          mips_jidctfst.c \
    LOCAL_MODULE := libjpeg


    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../jpeg/src/main/jni
    LOCAL_MODULE     := processor
    LOCAL_SRC_FILES := [truncated]
    LOCAL_C_INCLUDES += [truncated]
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/processor/include
    LOCAL_LDLIBS += -lz

    When I run ndk-build it will successfully build jpeg when it gets to the processor build. It will however fail to build any code referencing jpeg (in processor) with undefined references such as:

    undefined reference to `jpeg_std_error(jpeg_error_mgr*)’

    I have a feeling I’m doing something slightly wrong in setting up the parent such that LOCAL_STATIC_LIBRARIES += libjpeg is not correctly importing. Anyone know what I might be doing wrong here?

  • Is it possible to change the radio button icon in an android radio button group
  • Convert AsyncTask to RxAndroid
  • Animate selector/state transitions
  • Controlling the camera to take pictures in portrait doesn't rotate the final images
  • Sending data from nested fragments to parent fragment
  • How to open adb and use it to send commands
  • One Solution collect form web for “Android ndk nested modules”

    Turns out I pulled the wrong jpeg header which didn’t have extern “C” to help with name mangling in c++. Fixing the header addressed the issue.

    Additionally, I had to reorganize the folder structure as nested NDK is a nightmare if all projects don’t fall under jni. It will start mangling LOCAL_PATH, wildcards, and basically any relative path.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.