Gradle could not find android_native_app_glue

I have a native library that I am trying to build with gradle. If I call the ndk-build command from the gradle file, I can create my own library. But if I try to use the ndk build function built into the android gradle plugin, I cannot build.

I get fatal error: android_native_app_glue.h: No such file or directory

The corresponding section of the gradle file is:

buildTypes.debug.jniDebugBuild true

defaultConfig {
    ndk {
      moduleName 'myModule'
      stl 'gnustl_static'
      cFlags '-UNDEBUG -Werror -Wunused-variable -Wunused-but-set-parameter -Wtype-limits -Wmissing-field-initializers -Wreturn-type -Wuninitialized'
      ldLibs 'log', 'GLESv2'
    }
    productFlavors {
      armv7{
        ndk {
          abiFilter 'armeabi-v7a'
        }
      }
    }
}

Is there a way to tell ndk to build where to find the android_native_app_glue.h file?

On a side note, is there a way to pass the verbose flag to ndk-build, equivalent ndk-build V=1?

+4
source share
3 answers

, , "-I{path_to_android-ndk}/sources/android/native_app_glue"
cFlags,

+3

- LOCAL_C_INCLUDES Android.mk, :

LOCAL_C_INCLUDES += /path/to/ndk/sources/android/native_app_glue

, , ls on /path/to/ndk/sources/android/native_app_glue/native_app_glue.h

0

Beginning with:

  • gradle -experimental: 0.6.0-alpha2
  • gradle -2.9-all.zip

One way to do this (or integrate any code that can be compiled and linked as a static library) is to create a new module in your project and change the gradle file of this module:

apply plugin: 'com.android.model.library'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"
        defaultConfig.with {
            minSdkVersion.apiLevel = 21
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "0.0.1"
        }
        compileOptions.with {
            sourceCompatibility=JavaVersion.VERSION_1_7
            targetCompatibility=JavaVersion.VERSION_1_7
        }
    }
    android.ndk {
        moduleName = "native-activity"
        cppFlags.add("-Werror")
        ldLibs.addAll(["log", "android"])
        stl        = "gnustl_static"
        ldFlags.add("-c")
    }
    android.sources {
        main {
            jni {
                source {
                    srcDir "${ndkDir}/sources/android/native_app_glue"
                }
            }
        }
    }
}

Then in your gradle.mk module you should simply add:

apply plugin: 'com.android.model.application'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')

model {
    android {
        [...]
    }
    android.ndk {
        [...]

        cppFlags.add("-I${file("${ndkDir}/sources/android/native_app_glue")}".toString())
    }
    android.sources {
        main {
            jni {
                dependencies {
                    project ":native-activity" linkage "static"
                }
            }
        }
    }
}

dependencies {
    compile project(':native-activity')
}
0
source

All Articles