Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Kotlin instead of Groovy for Android build configuration #2902

Merged
merged 10 commits into from
Oct 10, 2024
2 changes: 1 addition & 1 deletion .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
cache-name: gradle-v1
with:
path: ~/.gradle
key: ${{ env.cache-name }}-${{ hashFiles('platform/android/gradle/dependencies.gradle') }}-${{ hashFiles('platform/android/build.gradle') }}-${{ hashFiles('platform/android/local.properties') }}-${{ hashFiles('platform/android/gradle/wrapper/gradle-wrapper.properties') }}
key: ${{ env.cache-name }}-${{ hashFiles('platform/android/buildSrc/src/main/kotlin/maplibre.dependencies.gradle.kts') }}-${{ hashFiles('platform/android/build.gradle.kts') }}-${{ hashFiles('platform/android/local.properties') }}-${{ hashFiles('platform/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
- ${{ env.cache-name }}

Expand Down
186 changes: 0 additions & 186 deletions platform/android/MapLibreAndroid/build.gradle

This file was deleted.

196 changes: 196 additions & 0 deletions platform/android/MapLibreAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import org.jetbrains.dokka.gradle.DokkaTask

plugins {
alias(libs.plugins.kotlinter)
alias(libs.plugins.dokka)
id("com.android.library")
id("com.jaredsburrows.license")
kotlin("android")
id("maplibre.download-vulkan-validation")
id("maplibre.gradle-checkstyle")
id("maplibre.gradle-dependencies-graph")
id("maplibre.android-nitpick")
id("maplibre.gradle-publish")
id("maplibre.artifact-settings")
}

dependencies {
lintChecks(project(":MapLibreAndroidLint"))
api(libs.maplibreJavaGeoJSON)
api(libs.maplibreGestures)

implementation(libs.maplibreJavaTurf)
implementation(libs.supportAnnotations)
implementation(libs.supportFragmentV4)
implementation(libs.okhttp3)
implementation(libs.timber)
implementation(libs.interpolator)

testImplementation(libs.junit)
testImplementation(libs.mockito)
testImplementation(libs.mockk)
testImplementation(libs.robolectric)
testImplementation(libs.commonsIO)
testImplementation(libs.assertjcore)

androidTestImplementation(libs.testRunner)
androidTestImplementation(libs.testRules)
}

tasks.withType<DokkaTask> {
moduleName.set("MapLibre Native Android")

dokkaSourceSets {
configureEach {
includes.from("Module.md")
}
}
}

android {
defaultConfig {
compileSdk = 34
minSdk = 21
targetSdk = 33
buildConfigField("String", "GIT_REVISION_SHORT", "\"${getGitRevision()}\"")
buildConfigField("String", "GIT_REVISION", "\"${getGitRevision(false)}\"")
buildConfigField(
"String",
"MAPLIBRE_VERSION_STRING",
"\"MapLibre Native/${project.property("VERSION_NAME")}\""
)
consumerProguardFiles("proguard-rules.pro")

externalNativeBuild {
cmake {
arguments("-DMLN_LEGACY_RENDERER=ON", "-DMLN_DRAWABLE_RENDERER=OFF")
}
}
}

flavorDimensions += "renderer"
productFlavors {
create("legacy") {
dimension = "renderer"
externalNativeBuild {
cmake {
arguments("-DMLN_LEGACY_RENDERER=ON", "-DMLN_DRAWABLE_RENDERER=OFF")
}
}
}
create("drawable") {
dimension = "renderer"
externalNativeBuild {
cmake {
arguments("-DMLN_LEGACY_RENDERER=OFF", "-DMLN_DRAWABLE_RENDERER=ON")
}
}
}
create("vulkan") {
dimension = "renderer"
externalNativeBuild {
cmake {
arguments("-DMLN_LEGACY_RENDERER=OFF", "-DMLN_DRAWABLE_RENDERER=ON")
arguments("-DMLN_WITH_OPENGL=OFF", "-DMLN_WITH_VULKAN=ON")
}
}
}
}

sourceSets {
getByName("legacy") {
java.srcDirs("src/opengl/java/")
}
getByName("drawable") {
java.srcDirs("src/opengl/java/")
}
}

// Build native libraries
val nativeTargets = mutableListOf("maplibre")
if (project.hasProperty("mapbox.with_test")) {
nativeTargets.add("mbgl-test")
}
if (project.hasProperty("mapbox.with_benchmark")) {
nativeTargets.add("mbgl-benchmark")
}
nativeBuild(nativeTargets)

// Avoid naming conflicts, force usage of prefix
resourcePrefix("maplibre_")

sourceSets {
getByName("main") {
res.srcDirs("src/main/res-public")
}
}

testOptions {
unitTests {
isReturnDefaultValues = true

// Robolectric 4.0 required config
// http://robolectric.org/migrating/#migrating-to-40
isIncludeAndroidResources = true
}
}

buildTypes {
getByName("debug") {
isTestCoverageEnabled = false
isJniDebuggable = true
// debuggable = true
louwers marked this conversation as resolved.
Show resolved Hide resolved
}
}

namespace = "org.maplibre.android"

lint {
checkAllWarnings = true
disable += listOf(
"MissingTranslation",
"TypographyQuotes",
"ObsoleteLintCustomCheck",
"MissingPermission",
"WrongThreadInterprocedural"
)
warningsAsErrors = false
}

buildFeatures {
buildConfig = true
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "11"
}
}

licenseReport {
generateHtmlReport = false
generateJsonReport = true
copyHtmlReportToAssets = false
copyJsonReportToAssets = false
}

fun getGitRevision(shortRev: Boolean = true): String {
val cmd = if (shortRev) "git rev-parse --short HEAD" else "git rev-parse HEAD"
val proc = Runtime.getRuntime().exec(cmd)
return proc.inputStream.bufferedReader().readText().trim()
}
//in gradle kotlin dsl checkstyle is failing due to this
/*configurations {
all {
exclude(group = "commons-logging", module = "commons-logging")
exclude(group = "commons-collections", module = "commons-collections")
}
}*/
louwers marked this conversation as resolved.
Show resolved Hide resolved
apply<DownloadVulkanValidationPlugin>()

// intentionally disabled
// apply(from = "${rootDir}/gradle/jacoco-report.gradle")
Loading
Loading