Gradle NDK指定' include'生成的Android.mk中的指令 [英] Gradle NDK to specify an 'include' directive in generated Android.mk

查看:128
本文介绍了Gradle NDK指定' include'生成的Android.mk中的指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有空

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

在您的build.gradle中,然后Gradle将编译src/main/jni/中的文件,并在build/ndk/debug/Android.mk中生成一个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命令时,我可以使用该工具.但是我想通过Gradle/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的Gradle插件中,我不确定如何在生成的Android.mk文件中添加此"include"指令.

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

谁能指出我正确的Gradle指令方向,以将此行添加到生成文件中?谢谢.

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

推荐答案

我发现构建过程将从./src/main/jni文件夹下面提取所有内容.因此,我将符号链接放在其他位置包括include和src文件夹-src文件将在构建过程中枚举到.mk文件中,而inc文件将由编译器获取.也许有点古怪:

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-studio进行构建.它将使用gradlew命令tho构建:

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"
            }
        }
    }
}

我希望它可以为您提供帮助(android-studio 0.8.6).

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

这篇关于Gradle NDK指定' include'生成的Android.mk中的指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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