Reputation: 1659
I am trying to run ndk-build from my build.gradle in an Android Studio 1.0 project on MAC OSX Yosemite.
task ndkBuild(type: Exec) {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
I have specified the ndk-dir in the local.properties file but I am getting this error
A problem occurred starting process 'command 'ndk-build'
If I run the gradle script from command line like this everything successfully builds
./gradlew :myproject:assembleDebug
So for some reason the IDE is unable to call ndk-build. I enabled some debug info in Android studio and I have the following error
Caused by: java.io.IOException: error=2, No such file or directory
So the IDE cannot find the ndk-build exe however running from the terminal inside the IDE the ndk-build exe can be found.
Thanks
Upvotes: 11
Views: 6752
Reputation: 163
EDIT
You can now retrieve the path like this :
android.ndkDirectory.getAbsolutePath()
I updated the sample below.
As you said in the comments, commandLine
requires the path of ndk-build program to make it work. Here is a way to retrieve the ndk path in build.gradle :
// call regular ndk-build script from app directory
task ndkBuild(type: Exec) {
def ndkDir = android.ndkDirectory.getAbsolutePath()
commandLine ndkDir + "/ndk-build", '-C', file('src/main').absolutePath
}
You will have a "cannot infer argument type" lint warning, You can safely ignore this warning. Add // noinspection GroovyAssignabilityCheck
to get rid of it.
This was tested with gradle 1.2.3
Upvotes: 16