co-maps/android/sdk/build.gradle
2025-11-22 13:58:55 +01:00

163 lines
4.7 KiB
Groovy

plugins {
id 'com.android.library'
}
android {
namespace = 'app.organicmaps.sdk'
compileSdk = propCompileSdkVersion.toInteger()
ndkVersion = '28.2.13676358'
buildFeatures {
buildConfig = true
}
defaultConfig {
minSdk = propMinSdkVersion.toInteger()
targetSdk = propTargetSdkVersion.toInteger()
externalNativeBuild {
def pchFlag = 'OFF'
if (project.hasProperty('pch')) pchFlag = 'ON'
def njobs = ''
if (project.hasProperty('njobs')) njobs = project.getProperty('njobs')
def enableVulkanDiagnostics = 'OFF'
if (project.hasProperty('enableVulkanDiagnostics')) {
enableVulkanDiagnostics = project.getProperty('enableVulkanDiagnostics')
}
def enableTrace = 'OFF'
if (project.hasProperty('enableTrace')) {
enableTrace = project.getProperty('enableTrace')
}
cmake {
cppFlags '-fexceptions', '-frtti'
// There is no sense to enable sections without gcc's --gc-sections flag.
cFlags '-fno-function-sections', '-fno-data-sections',
'-Wno-extern-c-compat'
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static',
'-DSKIP_TESTS=ON', '-DSKIP_TOOLS=ON', "-DUSE_PCH=$pchFlag",
"-DNJOBS=$njobs", "-DENABLE_VULKAN_DIAGNOSTICS=$enableVulkanDiagnostics",
"-DENABLE_TRACE=$enableTrace"
targets 'organicmaps'
}
}
// Use, for example, -Parm32 gradle parameter to build only for armeabi-v7a.
ndk {
abiFilters = new HashSet<>()
if (project.hasProperty('arm32') || project.hasProperty('armeabi-v7a')) {
abiFilters.add('armeabi-v7a')
}
if (project.hasProperty('arm64') || project.hasProperty('arm64-v8a')) {
abiFilters.add('arm64-v8a')
}
if (project.hasProperty('x86')) {
abiFilters.add('x86')
}
if (project.hasProperty('x86_64') || project.hasProperty('x64')) {
abiFilters.add('x86_64')
}
if (abiFilters.isEmpty()) {
abiFilters.add('armeabi-v7a')
abiFilters.add('arm64-v8a')
// For the emulator, chromebooks and some Intel Atom devices.
abiFilters.add('x86_64')
}
println('Building for ' + abiFilters + ' archs.')
}
}
buildTypes {
debug {
jniDebuggable true // Enable jni debug build
}
release {
// minifyEnabled true
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
beta {
// minifyEnabled true
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
matchingFallbacks = ['release']
}
}
externalNativeBuild {
cmake {
version = '3.22.1+'
buildStagingDirectory './nativeOutputs'
path '../../CMakeLists.txt'
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
lint {
disable 'MissingTranslation'
// https://github.com/organicmaps/organicmaps/issues/3551
disable 'MissingQuantity', 'UnusedQuantity'
// https://github.com/organicmaps/organicmaps/issues/3550
disable 'ByteOrderMark'
// https://github.com/organicmaps/organicmaps/issues/1077
disable 'CustomSplashScreen'
// https://github.com/organicmaps/organicmaps/issues/3610
disable 'InsecureBaseConfiguration'
abortOnError = true
}
}
dependencies {
coreLibraryDesugaring libs.android.tools.desugar
implementation libs.androidx.core
implementation libs.androidx.annotation
implementation libs.androidx.fragment
implementation libs.androidx.lifecycle.process
implementation libs.androidx.media
implementation libs.androidx.recyclerview
implementation libs.android.material
testImplementation libs.junit
}
// TODO: Running lint task triggers native build. Find a better solution.
project.afterEvaluate {
boolean isLintRun = project.gradle.startParameter.taskNames.any { it.toLowerCase().contains('lint') }
if (isLintRun) {
tasks.findAll { task ->
(task.name.startsWith('Native') || task.name.contains('CMake')) &&
task.project == project
}.each { nativeTask ->
logger.warn("Disabling task ${nativeTask.path} because lint is running.")
nativeTask.onlyIf { false }
}
}
final taskName = gradle.startParameter.taskNames
if (['assemble', 'bundle', 'compile', 'install', 'run'].any{taskName.any{task->task.startsWith(it)}}) {
exec {
workingDir '../..'
if (!taskName.toString().contains('Google')) {
environment 'SKIP_MAP_DOWNLOAD', '1'
}
commandLine './configure.sh'
}
}
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation'
}