Skip to content

Commit c90d823

Browse files
[google_maps_flutter] Enable -Werror for Android (flutter#3399)
[google_maps_flutter] Enable -Werror for Android
1 parent c40f189 commit c90d823

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/GoogleMapControllerTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.flutter.plugin.common.MethodCall;
2323
import io.flutter.plugin.common.MethodChannel;
2424
import java.util.HashMap;
25+
import org.junit.After;
2526
import org.junit.Assert;
2627
import org.junit.Before;
2728
import org.junit.Test;
@@ -41,19 +42,32 @@ public class GoogleMapControllerTest {
4142
private ComponentActivity activity;
4243
private GoogleMapController googleMapController;
4344

45+
AutoCloseable mockCloseable;
4446
@Mock BinaryMessenger mockMessenger;
4547
@Mock GoogleMap mockGoogleMap;
4648

4749
@Before
4850
public void before() {
49-
MockitoAnnotations.initMocks(this);
51+
mockCloseable = MockitoAnnotations.openMocks(this);
5052
context = ApplicationProvider.getApplicationContext();
51-
activity = Robolectric.setupActivity(ComponentActivity.class);
53+
setUpActivityLegacy();
5254
googleMapController =
5355
new GoogleMapController(0, context, mockMessenger, activity::getLifecycle, null);
5456
googleMapController.init();
5557
}
5658

59+
// TODO(stuartmorgan): Update this to a non-deprecated test API.
60+
// See https://github.com/flutter/flutter/issues/122102
61+
@SuppressWarnings("deprecation")
62+
private void setUpActivityLegacy() {
63+
activity = Robolectric.setupActivity(ComponentActivity.class);
64+
}
65+
66+
@After
67+
public void tearDown() throws Exception {
68+
mockCloseable.close();
69+
}
70+
5771
@Test
5872
public void DisposeReleaseTheMap() throws InterruptedException {
5973
googleMapController.onMapReady(mockGoogleMap);

packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/MarkersControllerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public void controller_OnMarkerDragStart() {
4242
when(googleMap.addMarker(any(MarkerOptions.class))).thenReturn(marker);
4343

4444
final LatLng latLng = new LatLng(1.1, 2.2);
45-
final Map<String, String> markerOptions = new HashMap();
45+
final Map<String, String> markerOptions = new HashMap<>();
4646
markerOptions.put("markerId", googleMarkerId);
4747

4848
final List<Object> markers = Arrays.<Object>asList(markerOptions);
4949
controller.addMarkers(markers);
5050
controller.onMarkerDragStart(googleMarkerId, latLng);
5151

52-
final List<Double> points = new ArrayList();
52+
final List<Double> points = new ArrayList<>();
5353
points.add(latLng.latitude);
5454
points.add(latLng.longitude);
5555

@@ -75,14 +75,14 @@ public void controller_OnMarkerDragEnd() {
7575
when(googleMap.addMarker(any(MarkerOptions.class))).thenReturn(marker);
7676

7777
final LatLng latLng = new LatLng(1.1, 2.2);
78-
final Map<String, String> markerOptions = new HashMap();
78+
final Map<String, String> markerOptions = new HashMap<>();
7979
markerOptions.put("markerId", googleMarkerId);
8080

8181
final List<Object> markers = Arrays.<Object>asList(markerOptions);
8282
controller.addMarkers(markers);
8383
controller.onMarkerDragEnd(googleMarkerId, latLng);
8484

85-
final List<Double> points = new ArrayList();
85+
final List<Double> points = new ArrayList<>();
8686
points.add(latLng.latitude);
8787
points.add(latLng.longitude);
8888

@@ -108,14 +108,14 @@ public void controller_OnMarkerDrag() {
108108
when(googleMap.addMarker(any(MarkerOptions.class))).thenReturn(marker);
109109

110110
final LatLng latLng = new LatLng(1.1, 2.2);
111-
final Map<String, String> markerOptions = new HashMap();
111+
final Map<String, String> markerOptions = new HashMap<>();
112112
markerOptions.put("markerId", googleMarkerId);
113113

114114
final List<Object> markers = Arrays.<Object>asList(markerOptions);
115115
controller.addMarkers(markers);
116116
controller.onMarkerDrag(googleMarkerId, latLng);
117117

118-
final List<Double> points = new ArrayList();
118+
final List<Double> points = new ArrayList<>();
119119
points.add(latLng.latitude);
120120
points.add(latLng.longitude);
121121

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ task clean(type: Delete) {
3535
gradle.projectsEvaluated {
3636
project(":google_maps_flutter_android") {
3737
tasks.withType(JavaCompile) {
38-
// TODO(stuartmorgan): Enable this. See
39-
// https://github.com/flutter/flutter/issues/91868
40-
//options.compilerArgs << "-Xlint:all" << "-Werror"
38+
// Ignore classfile warnings due to https://bugs.openjdk.org/browse/JDK-8190452
39+
// TODO(stuartmorgan): Remove that ignore once the build uses Java 11+.
40+
options.compilerArgs << "-Xlint:all" << "-Werror" << "-Xlint:-classfile"
41+
// Workaround for a warning when building that the above turns into
42+
// an error, coming from jetified-play-services-maps-18.1.0:
43+
// warning: Cannot find annotation method 'value()' in type
44+
// 'GuardedBy': class file for
45+
// javax.annotation.concurrent.GuardedBy not found
46+
dependencies {
47+
implementation "com.google.code.findbugs:jsr305:3.0.2"
48+
}
4149
}
4250
}
4351
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
org.gradle.jvmargs=-Xmx4G
2-
android.enableR8=true
32
android.useAndroidX=true
43
android.enableJetifier=true
5-

0 commit comments

Comments
 (0)