ext.nativeBuild = { nativeTargets -> android { defaultPublishConfig project.hasProperty("mapbox.buildtype") ? project.getProperty("mapbox.buildtype") : "debug" // We sometimes want to invoke Gradle without building a native dependency, e.g. when we just want // to invoke the Java tests. When we explicitly specify an ABI of 'none', no native dependencies are // added. When another ABI is specified explicitly, we're just going to build that ABI. In all other // cases, all ABIs are built. // // When invoking from the command line or to override the device default, set `-Pmapbox.abis=...` to // only build the desired architectures. // // When building from Android Studio, gradle.properties sets `android.buildOnlyTargetAbi=true` so that // only the architecture for the device you're running on gets built. def abi = 'all' if (!project.hasProperty('android.injected.invoked.from.ide') && project.hasProperty("mapbox.abis")) { // Errors when the user invokes Gradle from the command line and didn't set mapbox.abis abi = project.getProperty("mapbox.abis") } if (abi != 'none') { externalNativeBuild { cmake { path "../MapboxGLAndroidSDK/src/cpp/CMakeLists.txt" version "3.10.2" } } } // Allow determining the C++ STL we're using when building Mapbox GL. def stl = 'c++_static' if (project.hasProperty("mapbox.stl")) { stl = project.getProperty("mapbox.stl") } defaultConfig { if (abi != 'none') { externalNativeBuild { cmake { arguments "-DANDROID_TOOLCHAIN=clang" arguments "-DANDROID_STL=" + stl arguments "-DANDROID_CPP_FEATURES=exceptions" // Enable ccache if the user has installed it. if (file("/usr/bin/ccache").exists()) { arguments "-DANDROID_CCACHE=/usr/bin/ccache" } else if (file("/usr/local/bin/ccache").exists()) { arguments "-DANDROID_CCACHE=/usr/local/bin/ccache" } cFlags "-Qunused-arguments" cppFlags "-Qunused-arguments" for (target in nativeTargets) { targets target } if (abi != 'all') { abiFilters abi.split(' ') } else { if (project.hasProperty('android.injected.invoked.from.ide') && project.hasProperty('android.injected.build.abi')) { //Only build the target abi while running from Android studio abi = project.getProperty("android.injected.build.abi") abiFilters abi.split(',').first() } else { abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } } } } } } }