Including External Headers in NDK


(Ian Howell) #1

I am currently trying to build my project with the source to an external library (along with the headers) in my Android/Gradle project. I am using gradle-experimental:0.7.2 and trying to figure out how to include the headers so that I don’t have to edit the library files. Basically I want <ft2build.h> to work like it does on ndk-build.

Project structure:

Project/
    app/
        build/
        src/
            main/
                java/
                jni/
                    freetype2-android/
                        Android.jni/
                        include/
                        src/
                    src/
                ...
        build.gradle
        ...
    build/
    gradle/
    build.gradle
    ...

And my build.gradle in the app module:

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = '23.0.2'

        defaultConfig.with {
            applicationId = 'com.example.SanAngeles'
            minSdkVersion.apiLevel = 9
            targetSdkVersion.apiLevel = 23
        }

        ndk {
            platformVersion = 9
            moduleName = 'sanangeles'
            toolchain = 'clang'
            CFlags.addAll(['-DANDROID_NDK', '-DDISABLE_IMPORTGL'])

            ldLibs.addAll(['android', 'log', 'dl', 'GLESv1_CM'])
            abiFilters.addAll(['armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'])
            stl "stlport_static"
        }

        sources.main {
            jni.source.srcDir 'app/src/main/jni/src'
        }
    }
}

So, how do I get the headers from freetype2-android/include into the search path. (Like the one in XCode)

Edit, more information I remembered.

I am able to build this using ndk-build and the following Android.mk file:

LOCAL_PATH := $(call my-dir)

# Project
include $(CLEAR_VARS)
LOCAL_MODULE := sanangeles

FREETYPE_INCLUDE := freetype2-android/include
LOCAL_C_INCLUDES := \
 $(FREETYPE_INCLUDE) \
 $(FREETYPE_INCLUDE)/freetype/ \
 $(FREETYPE_INCLUDE)/freetype/config \
 $(FREETYPE_INCLUDE)/freetype/internal \
 $(FREETYPE_INCLUDE)/freetype/internal/services
LOCAL_STATIC_LIBRARIES := freetype

LOCAL_LDLIBS := -landroid -lEGL -lGLESv2 -ldl

LOCAL_CFLAGS := -DANDROID_NDK -DDISABLE_IMPORTGL

LOCAL_SRC_FILES := \
    src/triangle.cpp \
    src/app-android.c \
    src/Helpers/ivec2.cpp \
    src/Helpers/vec3.cpp \
    src/Renderers/BoxRenderer.cpp \
    src/Renderers/TextRenderer.cpp \
    src/Renderers/Shader.cpp

include $(BUILD_SHARED_LIBRARY)