8

I was using the this method to get the NDK directory:

project.plugins.findPlugin('com.android.library').sdkHandler.getNdkFolder()

Ater updating com.android.tools.build:gradle to 2.3 the field sdkHandler seems to have been renamed on removed

Error:No such property: sdkHandler for class: com.android.build.gradle.LibraryPlugin

Is there an alternative way to get the NDK directory path in a library module?

Marcin Kunert
  • 5,596
  • 5
  • 26
  • 52

4 Answers4

12

This method will now return the NDK's full path:

project.android.ndkDirectory.absolutePath
Tjaart
  • 496
  • 8
  • 20
1

For me the fix was to simply set the ANDROID_NDK environment variable. More here.

Vaiden
  • 15,728
  • 7
  • 61
  • 91
0

I've done some digging. Seems that the field is still there but marked as private.

One solution would be to use reflection.

The field is in com.android.build.gradle.BasePlugin from which com.android.build.gradle.LibraryPlugin inherits.

LibraryPlugin plugin = project.plugins.findPlugin('com.android.library')
Class<?> clazz = plugin.getClass().getSuperclass();
Field field = clazz.getDeclaredField('sdkHandler')
field.setAccessible(true)
SdkHandler sdkHandler = field.get(plugin)
System.out.println("Ndk location: " + sdkHandler.getNdkFolder())

To be honest i don't really like this solution. I hope to find a better one.

Marcin Kunert
  • 5,596
  • 5
  • 26
  • 52
-2

Just downgrade your gradle version to 2.2.3. it will solve the problem

ArunKumar
  • 47
  • 1
  • 6