Search code examples
androidandroid-studioandroid-ndkndk-build

In Android Studio what is the equivalent of CMAKE_VERBOSE_MAKEFILE under ndk-build?


I am trying to push some existing Android.mk-based native code into a new Android Studio app. There are some linking errors that give the message "Error:error: linker command failed with exit code 1 (use -v to see invocation)". When using CMake, one can set the variable CMAKE_VERBOSE_MAKEFILE to make this the default behavior. Is there a way to do something similar under ndk-build? Trying to run ndk-build from the command line with -v or V=1 (not sure which is best) in an Android Studio context seems awkward.

Edit:

As noted in the response below, this should be possible from Gradle using the "arguments" keyword. My interpretation of this is this version of the Module: app build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.adth.jwc.testproj4"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path "$projectDir/jni/Android.mk"
            arguments "V=1"
       }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
}

This generates the error message "Error:(16, 0) Could not find method ndkBuild() for arguments [build_95llvy1tc979yxena3spokoe8$_run_closure1$_closure3@34646897] on root project 'TestProj4' of type org.gradle.api.Project."

I have also tried some variations, all of which generate essentially the same error. What is the correct placement of the "arguments" keyword in the build.gradle file?


Solution

  • From the DSL reference, it looks like you need to put the exernalNativeBuild block in a product flavor or build type block to add arguments, so

    defaultConfig {
        applicationId "com.adth.jwc.testproj4"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            ndkBuild {
                arguments "V=1"
            }
        }
    }
    

    should work. Confusingly, BaseExtension (the android block) can also have an externalNativeBuild block, but its ndkBuild property is an NdkBuildOptions object, which only has a path property. The ndkBuild blocks for flavors and build types are ExternalNativeNdkBuildOptions objects, which have arguments etc.