Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run ndk-build on Android studio from gradle on osx yosemite

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

like image 357
tech74 Avatar asked Dec 17 '14 07:12

tech74


People also ask

How do I configure the NDK of the Android Gradle plugin?

The steps vary according to the version of AGP used in the project. Find the Android Gradle Plugin version in either of the following locations: Select the version below: You have the following options to configure the NDK: (Recommended) Use the ndkVersion property to set the NDK version. Do not set any property.

How do I install the NDK in Android Studio?

Android Studio will automatically download the default version of the NDK for that specific AGP version (in this case, NDK version 21.0.6113669) or you can install the NDK from the command line. Android Studio installs all versions of the NDK in the android-sdk /ndk/ directory.

How do I install Gradle on Xcode?

Install the Command Line Tools: xcode-select --install Run the command xcode-select --install to install Command Line Tool before installing gradle. Once Xcode tool is installed retry the command: brew install gradle code2care@mac ~ % gradle Welcome to Gradle 6.8.3!

Which NDK version should I use to build my projects?

For AGP version 3.6 and above, that NDK version will be used to build your projects if you do NOT specify an NDK version in the build.gradle file. The default NDK version is documented inside the AGP release notes.


1 Answers

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

like image 160
hbrc Avatar answered Oct 21 '22 13:10

hbrc