NDK compilation works on android studio but not on intellij

I get the following error when I try to compile an android project with native libs using ndk

Error:Gradle: Execution failed for task ':greekWpa:buildNative'.
> Process 'command 'C:\Users\Thanos\android-ndk-r10d\ndk-build.cmd'' finished with non-zero exit value 2


On Android studio in compiles just fine. So is there anything I can do to fix it on intellij? Here's my gradle code for native libs too

task buildNative(type: Exec) {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkDir = properties.getProperty('ndk.dir')
    def ndkBuild = ndkDir + File.separator + "ndk-build.cmd";
    def ndkBuildingDir = new File("app/src/main");

    commandLine ndkBuild, '-C', ndkBuildingDir.absolutePath
}

tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn buildNative }
5 comments
Comment actions Permalink

Does it work as you expect if you run buildNative task using Gradle Tool Window?

Does it help if you define ndkBuildingDir as file("app/src/main")?

task buildNative(type: Exec) {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkDir = properties.getProperty('ndk.dir')
    def ndkBuild = ndkDir + File.separator + "ndk-build.cmd";
    def ndkBuildingDir = file("app/src/main");

    commandLine ndkBuild, '-C', ndkBuildingDir.absolutePath
}
0
Comment actions Permalink

Hi,

No it fails with the same error when I run the buildNative task from gradle window.
And No, the file with lowercase "f" doesn't make any difference

0
Comment actions Permalink

It was my mistake, remove "app" in the path (if you define the task for the "app" sub-project), actually the fix is to specify absolute path here and do not depend on current working dir:

 def ndkBuildingDir = file("src/main");
If the task will fail, add ''--info" parameter and post the output of the task here


task-info.png
0
Comment actions Permalink

Thank you so much for your help! Removing the "app" from the path made it compile successfully both on android studio and on intellij. But this makes me wonder what if I had multiple modules (e.g app2, app3) How could I refer to those if I don't put their name on the file path?
But thanks anyway I'll mark my question as answered :)

0

Please sign in to leave a comment.