简体   繁体   中英

gradle android ndk build

I'm trying to build the cocos2dx c++ project on android using gradle (previously it was ant ). I want to have two gradle tasks:

1) build c++ and Java. I found solution

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

2) build Java without cpp. How?

Note. With ant I can define two targets:

<!-- 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? It seems that ant is more flexible then 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).

I suggest following this tutorial , which will show you how to force gradle to use an Android.mk file. 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.

This document explains various aspects of Android.mk files so that you can better understand how you want to build. There are loads of options for building and it's much easier to control.

Good luck! I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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