Gradle android ndk build

I am trying to create a cocos2dx c ++ project in android using gradle

(previously it was ant

). I want to have two gradle tasks:

1) build C ++ and Java. I found a 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 this using gradle? Ant seems to be more flexible than gradle ..

+3


source to share


1 answer


Hmm ... I think you might want a more flexible solution to be honest. Using the NDK with Gradle is not the best, and there are ways to add extra flexibility to native builds without losing the other benefits of using Gradle (for example, using a supported Android IDE starting 6/30/2015, Android studio).

I offer this tutorial which will show you how to get Gradle to use the Android.mk file. These files provide much more flexibility through the use of modules that can be modified as needed. I would totally suggest compiling your C ++ library elsewhere into .so files, which might give you a little more room to breathe 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 many options for building and it is much easier to control.

Good luck! Hope this helps.

+1


source







All Articles