Skip to content

Commit ac617c1

Browse files
[google_maps_fluter] Switch to Kotlin Pigeon (#11522)
Replaces the Java Pigeon generator with the Kotlin Pigeon generator, and adjusts the project accordingly: - Adds Kotlin build setings to Gradle. - Updates API signatures and number handling for Kotlin/Java generator differences. - Adds generic Java/Kotlin compat shim to create Result objects from Java, since those haven't been added to the Pigeon generator yet. - Updates tests to use constructors instead of builders, since the Kotlin generator doesn't create builders. - In two cases where replacing the builder pattern would have required major changes, I instead pulled the builders from the old Java generation into the test files. - Updates tests to use a Java/Kotlin compat shim to read Kotlin Result values, instead of mocking the Java Pigeon response object. Part of flutter/flutter#158287 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent e0f15e0 commit ac617c1

35 files changed

Lines changed: 6485 additions & 10844 deletions

.ci/legacy_project/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ and then deleting everything but `android/` from it:
5252
imperative apply (this includes moving where the Android Gradle
5353
Plugin (AGP) version is set from `build.gradle` to `settings.gradle`).
5454
- Modifies `settings.gradle` to upgrade the Kotlin Gradle Plugin (KGP)
55-
from version 1.9.0 to 2.1.0. If a user runs into an error with the AGP version,
55+
from version 1.9.0 to 2.2.20. If a user runs into an error with the AGP version,
5656
the warning is clear on how to upgrade the version to one that we support.
5757
- Modifies `gradle.properties` to not set android.enableJetifier=true.
5858
- Update `app/build.gradle` to enable library desugaring to support

.ci/legacy_project/all_packages/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pluginManagement {
2020
plugins {
2121
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
2222
id "com.android.application" version "8.9.1" apply false
23-
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
23+
id "org.jetbrains.kotlin.android" version "2.2.20" apply false
2424
}
2525

2626
include ":app"

packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.19.8
2+
3+
* Updates internal implementation to use Kotlin Pigeon.
4+
15
## 2.19.7
26

37
* Fixes warnings in Java code.

packages/google_maps_flutter/google_maps_flutter_android/android/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
group = "io.flutter.plugins.googlemaps"
24
version = "1.0-SNAPSHOT"
35

46
buildscript {
7+
val kotlinVersion = "2.3.20"
58
repositories {
69
google()
710
mavenCentral()
811
}
912

1013
dependencies {
1114
classpath("com.android.tools.build:gradle:8.13.1")
15+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
1216
}
1317
}
1418

@@ -21,6 +25,13 @@ allprojects {
2125

2226
plugins {
2327
id("com.android.library")
28+
id("kotlin-android")
29+
}
30+
31+
kotlin {
32+
compilerOptions {
33+
jvmTarget = JvmTarget.fromTarget(JavaVersion.VERSION_17.toString())
34+
}
2435
}
2536

2637
android {

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/CirclesController.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import com.google.android.gms.maps.GoogleMap;
1010
import com.google.android.gms.maps.model.Circle;
1111
import com.google.android.gms.maps.model.CircleOptions;
12-
import io.flutter.plugins.googlemaps.Messages.MapsCallbackApi;
1312
import java.util.HashMap;
1413
import java.util.List;
1514
import java.util.Map;
15+
import kotlin.Result;
16+
import kotlin.Unit;
1617

1718
class CirclesController {
1819
@VisibleForTesting final Map<String, CircleController> circleIdToController;
@@ -32,14 +33,14 @@ void setGoogleMap(GoogleMap googleMap) {
3233
this.googleMap = googleMap;
3334
}
3435

35-
void addCircles(@NonNull List<Messages.PlatformCircle> circlesToAdd) {
36-
for (Messages.PlatformCircle circleToAdd : circlesToAdd) {
36+
void addCircles(@NonNull List<PlatformCircle> circlesToAdd) {
37+
for (PlatformCircle circleToAdd : circlesToAdd) {
3738
addCircle(circleToAdd);
3839
}
3940
}
4041

41-
void changeCircles(@NonNull List<Messages.PlatformCircle> circlesToChange) {
42-
for (Messages.PlatformCircle circleToChange : circlesToChange) {
42+
void changeCircles(@NonNull List<PlatformCircle> circlesToChange) {
43+
for (PlatformCircle circleToChange : circlesToChange) {
4344
changeCircle(circleToChange);
4445
}
4546
}
@@ -59,15 +60,15 @@ boolean onCircleTap(String googleCircleId) {
5960
if (circleId == null) {
6061
return false;
6162
}
62-
flutterApi.onCircleTap(circleId, new NoOpVoidResult());
63+
flutterApi.onCircleTap(circleId, (Result<Unit> result) -> Unit.INSTANCE);
6364
CircleController circleController = circleIdToController.get(circleId);
6465
if (circleController != null) {
6566
return circleController.consumeTapEvents();
6667
}
6768
return false;
6869
}
6970

70-
void addCircle(@NonNull Messages.PlatformCircle circle) {
71+
void addCircle(@NonNull PlatformCircle circle) {
7172
CircleBuilder circleBuilder = new CircleBuilder(density);
7273
String circleId = Convert.interpretCircleOptions(circle, circleBuilder);
7374
CircleOptions options = circleBuilder.build();
@@ -81,7 +82,7 @@ private void addCircle(String circleId, CircleOptions circleOptions, boolean con
8182
googleMapsCircleIdToDartCircleId.put(circle.getId(), circleId);
8283
}
8384

84-
private void changeCircle(@NonNull Messages.PlatformCircle circle) {
85+
private void changeCircle(@NonNull PlatformCircle circle) {
8586
String circleId = circle.getCircleId();
8687
CircleController circleController = circleIdToController.get(circleId);
8788
if (circleController != null) {

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/ClusterManagersController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import com.google.maps.android.clustering.view.DefaultAdvancedMarkersClusterRenderer;
2020
import com.google.maps.android.clustering.view.DefaultClusterRenderer;
2121
import com.google.maps.android.collections.MarkerManager;
22-
import io.flutter.plugins.googlemaps.Messages.MapsCallbackApi;
23-
import io.flutter.plugins.googlemaps.Messages.PlatformMarkerType;
2422
import java.util.HashMap;
2523
import java.util.List;
2624
import java.util.Map;
2725
import java.util.Set;
26+
import kotlin.Result;
27+
import kotlin.Unit;
2828

2929
/**
3030
* Controls cluster managers and exposes interfaces for adding and removing cluster items for
@@ -107,8 +107,8 @@ private void initListenersForClusterManager(
107107
}
108108

109109
/** Adds new ClusterManagers to the controller. */
110-
void addClusterManagers(@NonNull List<Messages.PlatformClusterManager> clusterManagersToAdd) {
111-
for (Messages.PlatformClusterManager clusterToAdd : clusterManagersToAdd) {
110+
void addClusterManagers(@NonNull List<PlatformClusterManager> clusterManagersToAdd) {
111+
for (PlatformClusterManager clusterToAdd : clusterManagersToAdd) {
112112
addClusterManager(clusterToAdd.getIdentifier());
113113
}
114114
}
@@ -216,7 +216,7 @@ void onClusterItemRendered(@NonNull MarkerBuilder item, @NonNull Marker marker)
216216
String clusterManagerId) {
217217
ClusterManager<MarkerBuilder> clusterManager = clusterManagerIdToManager.get(clusterManagerId);
218218
if (clusterManager == null) {
219-
throw new Messages.FlutterError(
219+
throw new FlutterError(
220220
"Invalid clusterManagerId",
221221
"getClusters called with invalid clusterManagerId:" + clusterManagerId,
222222
null);
@@ -238,7 +238,8 @@ public boolean onClusterClick(Cluster<MarkerBuilder> cluster) {
238238
MarkerBuilder[] builders = cluster.getItems().toArray(new MarkerBuilder[0]);
239239
String clusterManagerId = builders[0].clusterManagerId();
240240
flutterApi.onClusterTap(
241-
Convert.clusterToPigeon(clusterManagerId, cluster), new NoOpVoidResult());
241+
Convert.clusterToPigeon(clusterManagerId, cluster),
242+
(Result<Unit> result) -> Unit.INSTANCE);
242243
}
243244

244245
// Return false to allow the default behavior of the cluster click event to occur.

0 commit comments

Comments
 (0)