简体   繁体   English

gradle android ndk build

[英]gradle android ndk build

I'm trying to build the cocos2dx c++ project on android using gradle (previously it was ant ). 我正在尝试使用gradle (之前是ant )在android上构建cocos2dx c ++项目。 I want to have two gradle tasks: 我想要两个gradle任务:

1) build c++ and Java. 1)构建c ++和Java。 I found solution 我找到了解决方案

task buildCpp(type: Exec) {
    commandLine ... // command
}
tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn buildCpp
}

2) build Java without cpp. 2)在没有cpp的情况下构建Java。 How? 怎么样?

Note. 注意。 With ant I can define two targets: 使用ant我可以定义两个目标:

<!-- Build all -->
<target name="buildAll"
            description="build all: ndkBuild -> javac"
            depends="setDebugFlagTrue, ndkBuild, buildJavaSigned"/>

<!-- Build Java only -->
<target name="buildJavaSigned"
        description="javac"
        depends="setDebugFlagFalse, clean, release"/>

How can I do it with gradle? 我怎么能用gradle做呢? It seems that ant is more flexible then gradle.. 似乎蚂蚁比gradle更灵活。

Hmm... I think you may want to have a more flexible solution, to be honest. 嗯......我想你可能想要一个更灵活的解决方案,说实话。 Gradle's usage of NDK is not the best and there are ways to add more flexibility to native builds without losing the other benefits of using gradle (such as using the supported IDE for Android, as of 6/30/2015, Android studio). Gradle对NDK的使用并不是最好的,并且有一些方法可以为本机构建添加更多灵活性,而不会失去使用gradle的其他好处(例如使用支持的Android for Android,截至2015年6月30日,Android工作室)。

I suggest following this tutorial , which will show you how to force gradle to use an Android.mk file. 我建议按照本教程 ,它将向您展示如何强制gradle使用Android.mk文件。 These files allow far more flexibility by utilizing modules which can be changed around the way you need them to build. 这些文件通过利用可以根据您需要的方式进行更改的模块来实现更大的灵活性。 I would fully suggest compiling your C++ library elsewhere into .so files, which can give you a little more room to breath and debug problems. 我完全建议将你的C ++库编译到.so文件中,这可以为你提供更多空间来调试和调试问题。

This document explains various aspects of Android.mk files so that you can better understand how you want to build. 本文档解释了Android.mk文件的各个方面,以便您可以更好地了解如何构建。 There are loads of options for building and it's much easier to control. 有许多建筑选项,它更容易控制。

Good luck! 祝好运! I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM