timezonemap icon indicating copy to clipboard operation
timezonemap copied to clipboard

Update for Gradle Version Catalog Kotlin DSL and Android Compose 2024

Open haraldrudell opened this issue 6 months ago • 1 comments

For modern 2024 Android Apps, ie. Kotlin 2.0.0, Kotlin DSL Gradle Version Catalog and Compose:

in Android Studio project file gradle/libs.versions.toml:

[versions]
tzmap = "4.5"
zJni = "1.5.6-4" # 240804
[libraries]
zstd-jni = { group = "com.github.luben", name = "zstd-jni", version.ref = "zJni" } # for timezonemap
time-zone-map = { group = "us.dustinj.timezonemap", name = "timezonemap", version.ref = "tzmap" } # requires zstd-jni

in Android Studio project file app/build.gradle.kts:

dependencies {
    implementation(libs.time.zone.map) {
        exclude(group = "com.github.luben", module = "zstd-jni")
    }
    implementation(libs.zstd.jni) {
        artifact {
            type = "aar"
        }
    }
}

In kotlin:

import us.dustinj.timezonemap.TimeZoneMap

// takes 11 s, may throw
val timeZoneMap = TimeZoneMap.forEverywhere()
// may be null, may throw
val tz = timeZoneMap.getOverlappingTimeZone(
                degreesLatitude,
                degreesLongitude,
            )
…
// “America/Los_Angeles”
timeZoneString = tz.zoneId
…
                // throws if time zone string is unknown
                val timeZone = TimeZone.of(timeZoneString)

I think this should be documented and implemented in the Android example project

haraldrudell avatar Aug 06 '24 01:08 haraldrudell