3

First of all, I have to admit I have quite experience with android and ndk, but gradle scripts is a new topic for me. I'm working on a project whose gradle scripts are already written (it is not my part) and work fine.

My problem is that a specific task seems not to find the property-defined ndk.dir, which is defined in a local.properties file.

The project structure is (simplified):

_ <project_root>
|_ <sub_project folder>
    ...
    |_ main
    |_ build.gradle
    |_ local.properties
|_ ...

The local.properties file looks like:

ndk.dir=/home/ubuntu/dev/android-ndk-r9c

And the problematic part of the task, defined in the build.gradle file of the structure, is below:

task buildNDKFlavorGooglePlayStore(type: Exec) {
    if (project.ext.has('ndk.dir') && (project.ext.get('ndk.dir') != null)) {
        ext.ndkBuild = new File((String)project.ext.get('ndk.dir'), 'ndk-build')
        executable ndkBuild
    } else {
        throw new GradleException('Reason: ndk.dir is missing in ' + projectDir + '/local.properties')
    }
(...)
}

When syncing the project, an error appears due to the gradle exception defined.

Can anyone help? Could you tell me if it's possible to debug it?

Thank you in advance. Don't hesitate to ask for extra information if necessary.

1
  • Have you tried gradle.properties instead of local.properties?
    – tim_yates
    Jan 29, 2015 at 19:31

1 Answer 1

7

This works for me:

def getNdkDir() {
    if (System.env.ANDROID_NDK_ROOT != null)
        return System.env.ANDROID_NDK_ROOT

    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkdir = properties.getProperty('ndk.dir', null)
    if (ndkdir == null)
        throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")

    return ndkdir
}

def getNdkBuildCmd() {
    def ndkbuild = getNdkDir() + "/ndk-build"
    if (Os.isFamily(Os.FAMILY_WINDOWS))
        ndkbuild += ".cmd"

    return ndkbuild
}

Look here for details.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.