Skip to content

Commit

Permalink
chore: upgrade to Kotlin 2.0.0 and Version Catalogues. (#251)
Browse files Browse the repository at this point in the history
* chore: updated Kotlin to 2.0.0

* chore: migration to Catalogue

* chore: BuildConfig back

* chore: updated Kotlin to 2.0.0

* chore: upgraded to gradle 8.4.1

* chore: set right minSdk

* chore: set right minSdk

---------

Co-authored-by: dkhawk <dkhawk@google.com>
Co-authored-by: Dale Hawkins <107309+dkhawk@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 6, 2024
1 parent a780206 commit f2c3f20
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 129 deletions.
18 changes: 11 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ plugins {
}

android {
compileSdk versions.android.compileSdk
compileSdk libs.versions.androidCompileSdk.get().toInteger()

defaultConfig {
applicationId "com.google.maps.android.ktx.demo"
minSdkVersion 24
targetSdkVersion versions.android.targetSdk
minSdkVersion libs.versions.androidMinSdk.get().toInteger()
targetSdkVersion libs.versions.androidTargetSdk.get().toInteger()
versionCode 1
versionName "1.0"
}

buildFeatures {
buildConfig = true
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -51,10 +55,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation deps.kotlin
implementation deps.androidx.appcompat
implementation deps.androidx.coreKtx
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.1'
implementation libs.kotlinStdlib
implementation libs.androidxAppcompat
implementation libs.androidxCoreKtx
implementation libs.lifecycleRuntimeKtx

// Instead of the lines below, regular apps would load these libraries from Maven according to
// the README installation instructions
Expand Down
93 changes: 51 additions & 42 deletions app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.SupportMapFragment
Expand Down Expand Up @@ -71,27 +74,29 @@ class MainActivity : AppCompatActivity() {
}

val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
lifecycle.coroutineScope.launchWhenCreated {
val googleMap = mapFragment.awaitMap()
if (!isRestore) {
googleMap.awaitMapLoad()
googleMap.animateCamera(
CameraUpdateFactory.newLatLngZoom(
london,
10F
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
val googleMap = mapFragment.awaitMap()
if (!isRestore) {
googleMap.awaitMapLoad()
googleMap.animateCamera(
CameraUpdateFactory.newLatLngZoom(
london,
10F
)
)
)
}
showMapLayers(googleMap)
addButtonClickListener(googleMap)
launch {
googleMap.cameraMoveStartedEvents().collect {
Log.d(TAG, "Camera moved - reason $it")
}
}
launch {
googleMap.cameraIdleEvents().collect {
Log.d(TAG, "Camera is idle.")
showMapLayers(googleMap)
addButtonClickListener(googleMap)
launch {
googleMap.cameraMoveStartedEvents().collect {
Log.d(TAG, "Camera moved - reason $it")
}
}
launch {
googleMap.cameraIdleEvents().collect {
Log.d(TAG, "Camera is idle.")
}
}
}
}
Expand All @@ -100,34 +105,38 @@ class MainActivity : AppCompatActivity() {
private suspend fun addButtonClickListener(googleMap: GoogleMap) {
findViewById<Button>(R.id.button_animate_camera).setOnClickListener {
currentLocation = if (currentLocation == london) sanFrancisco else london
lifecycle.coroutineScope.launchWhenStarted {
googleMap.run {
awaitAnimateCamera(CameraUpdateFactory.newCameraPosition(
cameraPosition {
target(currentLocation)
zoom(0.0f)
tilt(0.0f)
bearing(0.0f)
}
))
awaitMapLoad()
awaitAnimateCamera(CameraUpdateFactory.newCameraPosition(
cameraPosition {
target(currentLocation)
zoom(10.0f)
bearing(180f)
tilt(75f)
build()
}
))
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
googleMap.run {
awaitAnimateCamera(CameraUpdateFactory.newCameraPosition(
cameraPosition {
target(currentLocation)
zoom(0.0f)
tilt(0.0f)
bearing(0.0f)
}
))
awaitMapLoad()
awaitAnimateCamera(CameraUpdateFactory.newCameraPosition(
cameraPosition {
target(currentLocation)
zoom(10.0f)
bearing(180f)
tilt(75f)
build()
}
))
}
}
}
}

findViewById<Button>(R.id.button_snapshot).setOnClickListener {
lifecycle.coroutineScope.launchWhenStarted {
val bitmap = googleMap.awaitSnapshot()
findViewById<ImageView>(R.id.image_view_snapshot).setImageBitmap(bitmap)
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
val bitmap = googleMap.awaitSnapshot()
findViewById<ImageView>(R.id.image_view_snapshot).setImageBitmap(bitmap)
}
}
}
}
Expand Down
63 changes: 11 additions & 52 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,24 @@

buildscript {
ext.versions = [
'android' : [
"buildTools": "30.0.3",
"compileSdk": 34,
"minSdk" : 19,
"targetSdk" : 34
],
'androidMapsUtils' : '3.8.2',
'androidx' : [
'appcompat': '1.1.0',
'coreKtx' : '1.2.0',
'espresso' : '3.2.0',
'test' : '1.2.0',
'junit' : '1.1.1',
],
'junit' : '4.12',
'kotlin' : '1.8.21',
'kotlinxCoroutines': '1.6.0',
'mockito' : '3.8.0',
'mockitoInline' : '5.2.0',
'mockitoKotlin' : '2.2.0',
'androidMapsSdk' : '18.2.0',
'volley' : '1.2.0',
]

ext.deps = [
'androidMapsUtils' : [
'gms': "com.google.maps.android:android-maps-utils:$versions.androidMapsUtils"
],
'androidx' : [
'appcompat': "androidx.appcompat:appcompat:$versions.androidx.appcompat",
'coreKtx' : "androidx.core:core-ktx:$versions.androidx.coreKtx",
'espresso' : "androidx.test.espresso:espresso-core:$versions.androidx.espresso",
'test' : "androidx.test:core:$versions.androidx.test",
'junit' : "androidx.test.ext:junit:$versions.androidx.junit"
],
'junit' : "junit:junit:$versions.junit",
'kotlin' : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin",
'kotlinxCoroutines': "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.kotlinxCoroutines",
'mockito' : "org.mockito:mockito-core:$versions.mockito",
'mockitoInline' : "org.mockito:mockito-inline:$versions.mockitoInline",
'mockitoKotlin' : "com.nhaarman.mockitokotlin2:mockito-kotlin:$versions.mockitoKotlin",
'playServices' : [
'maps' : "com.google.android.gms:play-services-maps:$versions.androidMapsSdk",
],
'volley' : "com.android.volley:volley:$versions.volley",

]
'android' : [
"buildTools": "30.0.3",
"compileSdk": 34,
"minSdk" : 21,
"targetSdk" : 34
]]

repositories {
gradlePluginPortal()
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.9.20'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
classpath 'com.mxalbert.gradle:jacoco-android:0.2.1'
classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1"
classpath libs.gradle
classpath libs.dokkaGradlePlugin
classpath libs.kotlinGradlePlugin
classpath libs.jacocoAndroid
classpath libs.secretsGradlePlugin
}
}

Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ kotlin.code.style=official
signing.keyId=
signing.password=
signing.secretKeyRingFile=

android.defaults.buildfeatures.buildconfig=true
sonatypeUsername=
sonatypePassword=

# Migration to AGP 8.2.1
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
49 changes: 49 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[versions]
androidCompileSdk = "34"
androidMapsSdk = "18.2.0"
androidMapsUtils = "3.8.2"
androidMinSdk = "21"
androidTargetSdk = "34"
androidxAppcompat = "1.7.0"
androidxCoreKtx = "1.13.1"
androidxJunit = "1.1.5"
androidxTest = "1.5.0"
dokkaGradlePlugin = "1.9.20"
gradle = "8.4.1"
jacocoAndroid = "0.2.1"
junit = "4.13.2"
kotlin = "2.0.0"
kotlinxCoroutines = "1.8.1"
lifecycleRuntimeKtx = "2.8.1"
mockito = "5.11.0"
kotlinGradlePlugin = "1.9.20"
mockitoInline = "5.2.0"
mockitoKotlin = "2.2.0"
secretsGradlePlugin = "2.0.1"

[libraries]
androidMapsUtils = { group = "com.google.maps.android", name = "android-maps-utils", version.ref = "androidMapsUtils" }
androidxAppcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppcompat" }
androidxCoreKtx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCoreKtx" }
androidxTest = { group = "androidx.test", name = "core", version.ref = "androidxTest" }
androidxJunit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxJunit" }
dokkaGradlePlugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokkaGradlePlugin" }
gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }
jacocoAndroid = { module = "com.mxalbert.gradle:jacoco-android", version.ref = "jacocoAndroid" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinGradlePlugin" }
kotlinStdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk7", version.ref = "kotlin" }
kotlinxCoroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" }
lifecycleRuntimeKtx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
mockitoInline = { group = "org.mockito", name = "mockito-inline", version.ref = "mockitoInline" }
mockitoKotlin = { group = "com.nhaarman.mockitokotlin2", name = "mockito-kotlin", version.ref = "mockitoKotlin" }
playServicesMaps = { group = "com.google.android.gms", name = "play-services-maps", version.ref = "androidMapsSdk" }
secretsGradlePlugin = { module = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin", version.ref = "secretsGradlePlugin" }

[plugins]
androidGradlePlugin = { id = "com.android.tools.build:gradle", version = "8.2.2" }
dokkaGradlePlugin = { id = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.9.20" }
jacocoAndroidPlugin = { id = "com.mxalbert.gradle:jacoco-android", version = "0.2.1" }
kotlinGradlePlugin = { id = "org.jetbrains.kotlin:kotlin-gradle-plugin", version = "2.0.0" }
secretsGradlePlugin = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version = "2.0.1" }
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Thu Jun 06 17:39:02 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
26 changes: 13 additions & 13 deletions maps-ktx/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google Inc.
* Copyright 2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,11 +19,11 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdk versions.android.compileSdk
compileSdk libs.versions.androidCompileSdk.get().toInteger()

defaultConfig {
minSdkVersion versions.android.minSdk
targetSdkVersion versions.android.targetSdk
minSdkVersion libs.versions.androidMinSdk.get().toInteger()
targetSdkVersion libs.versions.androidTargetSdk.get().toInteger()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
Expand All @@ -44,15 +44,15 @@ android {
}

dependencies {
implementation deps.kotlin
implementation deps.kotlinxCoroutines
api deps.playServices.maps
implementation libs.kotlinStdlib
implementation libs.kotlinxCoroutines
api libs.playServicesMaps

// Tests
testImplementation deps.androidx.test
testImplementation deps.androidx.junit
testImplementation deps.junit
testImplementation deps.mockito
testImplementation deps.mockitoKotlin
testImplementation deps.mockitoInline
testImplementation libs.androidxTest
testImplementation libs.androidxJunit
testImplementation libs.junit
testImplementation libs.mockito
testImplementation libs.mockitoKotlin
testImplementation libs.mockitoInline
}
Loading

0 comments on commit f2c3f20

Please sign in to comment.