NDK摇篮中产生的Andr​​oid.mk指定'包括'指令 [英] Gradle NDK to specify an 'include' directive in generated Android.mk

查看:114
本文介绍了NDK摇篮中产生的Andr​​oid.mk指定'包括'指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你有

android {
  defaultConfig {
    ndk {
                moduleName "yourlib"
                stl "stlport_static"
                ldLibs "log", "z", "m"
                cFlags "-I/some/include/dir/"
        }
    ...
  }
  ...
}

在你build.gradle那么摇篮将编译文件在src / main / JNI /,它会产生一个Android.mk在建/ NDK /调试/ Android.mk。

in your build.gradle then Gradle will compile the files in src/main/jni/ and it will generate an Android.mk in build/ndk/debug/Android.mk.

不过,在我的情况,我试图编译编译的OpenCV的一些C ++文件。

However, in my case, I'm trying to compile some C++ files compiled against OpenCV.

我有这样的工作时,我手动创建Android.mk文件并运行NDK-build命令。但我想通过摇篮做到这一点/ Android的Studio自动。

I have this working when I manually create the Android.mk file and run the ndk-build command. But I want to do it via Gradle / Android Studio automatically.

在手动这样做,我有反对链接库。我这样做,在手动创建Android.mk,用线:

When doing this manually, I include the libraries to link against. I do this, in the manually created Android.mk, with the line:

include /path/to/the/opencv/directory/sdk/native/jni/OpenCV.mk

不过,在Android的摇篮插件,我不确定如何添加这个'包括'指令在生成的Andr​​oid.mk文件。

However, in Android's Gradle plugin, I am unsure of how to add this 'include' directive in the generated Android.mk file.

任何人都可以点我在正确的摇篮,指示方向,以添加此行到生成的文件?谢谢你。

Can anyone point me in the right Gradle-directive direction to add this line to the generate file? Thanks.

推荐答案

我发现,构建过程会从下面的./src/main/jni文件夹拉的一切研究。所以,我已经放在符号链接有包括和src的文件夹在别处 - 在src文件将被列举到的.mk文件的生成过程和增量文件将被挖出了由编译器。也许它有点哈克:

I've found that that the build process will pull everything in from below the ./src/main/jni folder. So, I've placed symlinks there to include and src folders elsewhere - the src files will be enumerated into the .mk file by the build process and the inc files will be scooped up by the compiler. Perhaps its a bit hacky:

android {
    defaultConfig {
        ndk {
            moduleName "yourlib"
            cFlags "-std=c99 -I${project.buildDir}/../src/main/jni/inc"
        }
        ...
    }
    ...
}

我也有,这取决于调试版本不同的CFLAGS。这似乎是有效的摇篮,但不希望建立与Android的工作室。它将建立与gradlew命令寿:

I also have different cFlags depending upon debug build. This seems to be valid gradle, but doesn't want to build with android-studio. It will build with the gradlew command tho:

android {
    defaultConfig {
        ndk {
            moduleName "yourlib"
            cFlags "-std=c99 -I${project.buildDir}/../src/main/jni/inc"
        }
        ...
    }
    ...
    buildTypes {
        release {
            debuggable false
            jniDebugBuild false
            ndk {
                moduleName "yourlib"
            }
        }
        debug {
            debuggable true
            jniDebugBuild true
            ndk {
                moduleName "yourlib"
                ldLibs "log"
                cFlags "-g -D_DEBUG"
            }
        }
    }
}

我希望它可以帮助你(机器人工作室0.8.6)。

I hope it can help you (android-studio 0.8.6).

这篇关于NDK摇篮中产生的Andr​​oid.mk指定'包括'指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆