Skip to content

Commit 12ac29a

Browse files
authored
feat: add navigation flavor to demo for SDK 7.x reproduction (#1680)
* feat: add navigation flavor to demo for SDK 7.x reproduction * docs: header * fix: enable core library desugaring for navigation flavor * fix: move GMS version meta-data to standard flavor manifest * docs: header * fix: remove GMS version from library manifest to support exclusion * fix: update CI SARIF paths after adding flavors * fix: explicit lint tasks and default flavor to resolve CI paths * fix: use consistent lint-results.sarif paths in CI * fix: update navigation SDK and use version catalog for desugaring * fix: update desugar-jdk-libs to 2.1.5
1 parent 4952609 commit 12ac29a

9 files changed

Lines changed: 133 additions & 25 deletions

File tree

.github/workflows/lint-report.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ jobs:
3737
uses: gradle/actions/setup-gradle@v4
3838

3939
- name: Run Android Lint
40-
run: ./gradlew lint
40+
run: ./gradlew :library:lintDebug :demo:lintStandardDebug
4141

4242
- name: Upload SARIF for library
4343
uses: github/codeql-action/upload-sarif@v3
4444
with:
45-
sarif_file: library/build/reports/lint-results-debug.sarif
45+
sarif_file: library/build/reports/lint-results.sarif
4646
category: library
4747

4848
- name: Upload SARIF for demo
4949
uses: github/codeql-action/upload-sarif@v3
5050
with:
51-
sarif_file: demo/build/reports/lint-results-debug.sarif
51+
sarif_file: demo/build/reports/lint-results.sarif
5252
category: demo

demo/build.gradle.kts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ android {
5252
compose = true
5353
}
5454

55+
compileOptions {
56+
isCoreLibraryDesugaringEnabled = true
57+
sourceCompatibility = JavaVersion.VERSION_17
58+
targetCompatibility = JavaVersion.VERSION_17
59+
}
60+
5561
kotlin {
5662
compilerOptions {
5763
jvmTarget.set(JvmTarget.JVM_17)
@@ -60,13 +66,31 @@ android {
6066
}
6167

6268
namespace = "com.google.maps.android.utils.demo"
69+
70+
flavorDimensions += "sdk"
71+
productFlavors {
72+
create("standard") {
73+
dimension = "sdk"
74+
isDefault = true
75+
}
76+
create("navigation") {
77+
dimension = "sdk"
78+
minSdk = 24 // Navigation SDK 7.x requires API 24+
79+
}
80+
}
6381
}
6482

6583
// [START maps_android_utils_install_snippet]
6684
dependencies {
85+
coreLibraryDesugaring(libs.desugar.jdk.libs)
6786
// [START_EXCLUDE silent]
68-
implementation(project(":library"))
87+
"standardImplementation"(project(":library"))
88+
"navigationImplementation"(project(":library")) {
89+
exclude(group = "com.google.android.gms", module = "play-services-maps")
90+
}
6991

92+
"navigationImplementation"(libs.navigation.sdk)
93+
7094
implementation(libs.appcompat)
7195
implementation(libs.lifecycle.extensions)
7296
implementation(libs.lifecycle.viewmodel.ktx)

demo/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
android:theme="@style/AppTheme"
4343
tools:ignore="GoogleAppIndexingWarning">
4444

45-
<meta-data
46-
android:name="com.google.android.gms.version"
47-
android:value="@integer/google_play_services_version" />
48-
4945
<!--
5046
To add your Maps API key to this project:
5147
1. Open the file local.properties under the root project

demo/src/main/java/com/google/maps/android/utils/demo/BaseDemoActivity.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import android.widget.Toast;
2424

2525
import androidx.annotation.NonNull;
26+
import androidx.fragment.app.Fragment;
2627
import androidx.fragment.app.FragmentActivity;
2728

2829
import com.google.android.gms.maps.GoogleMap;
2930
import com.google.android.gms.maps.GoogleMapOptions;
3031
import com.google.android.gms.maps.OnMapReadyCallback;
31-
import com.google.android.gms.maps.SupportMapFragment;
3232

3333
import androidx.core.graphics.Insets;
3434
import androidx.core.view.ViewCompat;
@@ -97,19 +97,16 @@ private void setUpMap(Bundle savedInstanceState) {
9797
// 2. Call the getMapId() method
9898
String mapId = app.getMapId();
9999

100-
// Create a new SupportMapFragment instance
101-
SupportMapFragment mapFragment;
102-
103-
if (mapId == null) {
104-
mapFragment = SupportMapFragment.newInstance();
105-
} else {
106-
// Create the map options
107-
GoogleMapOptions mapOptions = new GoogleMapOptions();
100+
// Create the map options
101+
GoogleMapOptions mapOptions = null;
102+
if (mapId != null) {
103+
mapOptions = new GoogleMapOptions();
108104
mapOptions.mapId(mapId);
109-
// Create a new SupportMapFragment instance
110-
mapFragment = SupportMapFragment.newInstance(mapOptions);
111105
}
112106

107+
// Use the provider to get the correct fragment for the current flavor
108+
Fragment mapFragment = MapFragmentProvider.getFragment(mapOptions);
109+
113110
// Add the fragment to the container (R.id.map)
114111
// Check savedInstanceState to prevent re-adding on rotation
115112
if (savedInstanceState == null) {
@@ -119,8 +116,14 @@ private void setUpMap(Bundle savedInstanceState) {
119116
.commit();
120117
}
121118

122-
// Get the map
123-
mapFragment.getMapAsync(this);
119+
// Get the map asynchronously. We use reflection because the fragment type
120+
// depends on the build flavor (SupportMapFragment or SupportNavigationFragment).
121+
try {
122+
mapFragment.getClass().getMethod("getMapAsync", OnMapReadyCallback.class)
123+
.invoke(mapFragment, this);
124+
} catch (Exception e) {
125+
e.printStackTrace();
126+
}
124127
}
125128

126129
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.maps.android.utils.demo;
18+
19+
import androidx.fragment.app.Fragment;
20+
import com.google.android.gms.maps.GoogleMapOptions;
21+
import com.google.android.libraries.navigation.SupportNavigationFragment;
22+
23+
public class MapFragmentProvider {
24+
public static Fragment getFragment(GoogleMapOptions options) {
25+
if (options == null) {
26+
return SupportNavigationFragment.newInstance();
27+
} else {
28+
return SupportNavigationFragment.newInstance(options);
29+
}
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2026 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
18+
<application>
19+
<meta-data
20+
android:name="com.google.android.gms.version"
21+
android:value="@integer/google_play_services_version" />
22+
</application>
23+
</manifest>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.maps.android.utils.demo;
18+
19+
import androidx.fragment.app.Fragment;
20+
import com.google.android.gms.maps.GoogleMapOptions;
21+
import com.google.android.gms.maps.SupportMapFragment;
22+
23+
public class MapFragmentProvider {
24+
public static Fragment getFragment(GoogleMapOptions options) {
25+
if (options == null) {
26+
return SupportMapFragment.newInstance();
27+
} else {
28+
return SupportMapFragment.newInstance(options);
29+
}
30+
}
31+
}

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ compose-bom = "2026.02.00"
3030
# --- Google Services (Maps) ---
3131
# Versions for Google Play Services libraries essential for map functionality.
3232
play-services-maps = "20.0.0"
33+
navigation-sdk = "7.6.0"
34+
desugar-jdk-libs = "2.1.5"
3335

3436
# --- Testing ---
3537
# Versions for unit and instrumented testing libraries.
@@ -84,6 +86,8 @@ material-icons-core = { group = "androidx.compose.material", name = "material-ic
8486
# --- Google Services (Maps) ---
8587
# Key libraries for integrating Google Maps and related services.
8688
play-services-maps = { module = "com.google.android.gms:play-services-maps", version.ref = "play-services-maps" }
89+
navigation-sdk = { module = "com.google.android.libraries.navigation:navigation", version.ref = "navigation-sdk" }
90+
desugar-jdk-libs = { module = "com.android.tools:desugar_jdk_libs_nio", version.ref = "desugar-jdk-libs" }
8791

8892
# --- Testing ---
8993
# Tools for running implementation validation and user interface tests.

library/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
xmlns:tools="http://schemas.android.com/tools">
2020
<!-- https://groups.google.com/group/adt-dev/browse_thread/thread/c059c0380998092b/6720093fb40fdaf9 -->
2121
<application>
22-
<meta-data
23-
android:name="com.google.android.gms.version"
24-
android:value="@integer/google_play_services_version" />
25-
2622
<provider
2723
android:name="androidx.startup.InitializationProvider"
2824
android:authorities="${applicationId}.androidx-startup"

0 commit comments

Comments
 (0)