10

I just updated android Gradle plugin to 1.1.0 from 1.0.0, and I got this error:

No signature of method: com.android.build.gradle.LibraryPlugin.getNdkFolder() is applicable for argument types: () values: []

I tried to find diff of gradle plugin 1.0.0 to 1.1.0 but couldn't find anywhere online.

Seems like getNdkFolder method has been either changed or removed.

Is there a replacement ? Or any other way to get NdkFolder ?

I'm using that method like this,

def ndkDir = project.plugins.findPlugin ( 'com.android.library' ).getNdkFolder ()

I have also filed an issue against tools team in Android issue tracker: https://code.google.com/p/android/issues/detail?id=152810

Thank you !

shaktiman_droid
  • 2,368
  • 1
  • 17
  • 32
  • you want to specify folder where the NDK is or folder where your projects jni code is? ndk.dir can go in 'local.properties' file along with 'sdk.dir' – Robert Rowntree Feb 20 '15 at 03:02
  • As a replacement to getNdkFolder() for build tools 2.3.0 and onwards, see this post [No sdkHandler field in LibraryPlugin after updating to build tools 2.3.0](https://stackoverflow.com/questions/42644226/no-sdkhandler-field-in-libraryplugin-after-updating-to-build-tools-2-3-0/42923520#42923520) – Tjaart Jun 14 '17 at 07:08

5 Answers5

20

You can get it like this:

plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
Michael Pardo
  • 2,590
  • 3
  • 24
  • 33
8

The correct way - android.ndkDirectory

The change from android.plugin.ndkFolder to android.ndkDirectory was documented in the technical doc Migrating Gradle Projects to version 1.0.0. In addition you should update your android plugin to 2.3.0.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

The sdkFolder is internal and will likely stop working just like ndkFolder stopped working.

Regarding experimental branches

Search around, the plugin is mature enough you'll have trouble finding reasons to use experimental branches with the NDK.

There is some discussion about an Experimental version of the plugin breaking ndkDirectory which is the documented way to access this value after 1.1. If that changes in a released version I'll update my answer, in the mean time if running experimental plugins is your thing you can hack your way around this bug/feature using @Alex Cohn's answer.

Cameron Lowell Palmer
  • 21,528
  • 7
  • 125
  • 126
  • Broken again with the shift to "experimental" plugin :( – Alex Cohn Sep 17 '15 at 15:42
  • According to the documentation this should still be correct so I would file a bug if I were you. A quick check yielded no open bug. – Cameron Lowell Palmer Sep 18 '15 at 16:45
  • What makes you believe that `android.ndkDirectory` was not part of the big change of the DSL for the next version of Android plugin? Anyways, I found an alternative approach: http://stackoverflow.com/a/32658072/192373 – Alex Cohn Sep 18 '15 at 17:49
  • The experimental plugin comes with a big red warning label that says anything could change. Until something is actually shipped/documented I don't think we should confuse the answer by adding in notes about experimental versions. In all likelihood it is a bug. – Cameron Lowell Palmer Sep 18 '15 at 18:14
  • 2
    The truth is, all the credits should go to [Riccardo Ciovati](http://stackoverflow.com/users/321354/riccardo-ciovati): *[How do i read properties defined in local.properties in build.gradle](http://stackoverflow.com/a/22012018/192373)* – Alex Cohn Sep 19 '15 at 09:55
  • @AlexCohn That is another way to do things, but not necessarily the best. Anytime you introduce strings as arguments to functions the world is little worse off. – Cameron Lowell Palmer Mar 05 '17 at 11:28
4

I am using gradle 2.2.3 version. The think that worked for me:

def ndkDir = project.android.ndkDirectory

Ref. Link: https://code.google.com/p/android/issues/detail?id=152810

sgupta
  • 535
  • 4
  • 8
3

If in the build.gradle file you can probably use this now that the bug referenced has been marked fixed.

project.android.ndkDirectory 

If you're in a custom Task or Plugin you'll want to use this

    def androidPluginExtension = project.getExtensions().getByName("android");
    // Use this for easily viewing the properties available in the extension.
    androidPluginExtension.properties.each { Object key, Object value ->
        logger.info("Extensionprop: ${key} ${value}")
    }
    String ndkDir = androidPluginExtension.getProperties().get("ndkDirectory");
    System.out.println("Using ndk dir: ${ndkDir}");

But remember that the Android Plugin would have had to have been initialized, so this will always work in a Task's execute method, but it may not work if Gradle hasn't parsed the Android DSL yet during the Gradle Configuration phase.

PaulR
  • 3,223
  • 1
  • 21
  • 32
1

As Michael Pardo mentioned, you can get it by *

plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()

*

, In case you receive the following error:

Error:(9, 0) Plugin with id com.android.library has not been used.

You can use the applied plugin : 'com.android.application', therefore the final code will be :

def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.ndkFolder
Davood Falahati
  • 1,474
  • 16
  • 34