5

I am trying to add arguments to cmake in order to follow the Android NDK instructions for using the address sanitiser. In the build.gradle file for the native module I therefore have the following:

externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
            arguments "-DANDROID_ARM_MODE=arm", "-DANDROID_STL=c++_shared"
            cppFlags "-fsanitize=address -fno-omit-frame-pointer"
        }
    }

When I try to sync my project (Android Studio v. 3.4.2, Win10) I get the error message:

ERROR: Gradle DSL method not found: 'arguments()'

I've searched the web but can't find any other mention of this problem with the 'arguments' method. I'm using gradle 3.4.2.

What am I missing?

Timmy K
  • 291
  • 1
  • 2
  • 14
  • 2
    Where is this `externalNativeBuild` block located? There is a difference between putting it directly inside `android {}` and putting it inside `android { defaultConfig {}}` (e.g. the second has an `arguments` property, while the first one does not). – Michael Aug 05 '19 at 15:26
  • Thanks this fixed it since I was in fact supposed to add it in defaultConfig. And mine was indeed a duplicate question – Timmy K Aug 06 '19 at 09:29

1 Answers1

31

There are two different Gradle DSL objects both named externalNativeBuild, but with different properties. See this and this.

So you need to set the appropriate properties on the appropriate object:

android {
    defaultConfig {
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_ARM_MODE=arm", "-DANDROID_STL=c++_shared"
                cppFlags "-fsanitize=address -fno-omit-frame-pointer"
            }
        }
    }

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}
leonheess
  • 16,068
  • 14
  • 77
  • 112
Michael
  • 57,169
  • 9
  • 80
  • 125