Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/lint-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Run Android Lint
run: ./gradlew lint
run: ./gradlew :library:lintDebug :demo:lintStandardDebug

- name: Upload SARIF for library
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: library/build/reports/lint-results-debug.sarif
sarif_file: library/build/reports/lint-results.sarif
category: library

- name: Upload SARIF for demo
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: demo/build/reports/lint-results-debug.sarif
sarif_file: demo/build/reports/lint-results.sarif
category: demo
26 changes: 25 additions & 1 deletion demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ android {
compose = true
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
Expand All @@ -60,13 +66,31 @@ android {
}

namespace = "com.google.maps.android.utils.demo"

flavorDimensions += "sdk"
productFlavors {
create("standard") {
dimension = "sdk"
isDefault = true
}
create("navigation") {
dimension = "sdk"
minSdk = 24 // Navigation SDK 7.x requires API 24+
}
}
}

// [START maps_android_utils_install_snippet]
dependencies {
coreLibraryDesugaring(libs.desugar.jdk.libs)
// [START_EXCLUDE silent]
implementation(project(":library"))
"standardImplementation"(project(":library"))
"navigationImplementation"(project(":library")) {
exclude(group = "com.google.android.gms", module = "play-services-maps")
}

"navigationImplementation"(libs.navigation.sdk)

implementation(libs.appcompat)
implementation(libs.lifecycle.extensions)
implementation(libs.lifecycle.viewmodel.ktx)
Expand Down
4 changes: 0 additions & 4 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<!--
To add your Maps API key to this project:
1. Open the file local.properties under the root project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;

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

// Create a new SupportMapFragment instance
SupportMapFragment mapFragment;

if (mapId == null) {
mapFragment = SupportMapFragment.newInstance();
} else {
// Create the map options
GoogleMapOptions mapOptions = new GoogleMapOptions();
// Create the map options
GoogleMapOptions mapOptions = null;
if (mapId != null) {
mapOptions = new GoogleMapOptions();
mapOptions.mapId(mapId);
// Create a new SupportMapFragment instance
mapFragment = SupportMapFragment.newInstance(mapOptions);
}

// Use the provider to get the correct fragment for the current flavor
Fragment mapFragment = MapFragmentProvider.getFragment(mapOptions);

// Add the fragment to the container (R.id.map)
// Check savedInstanceState to prevent re-adding on rotation
if (savedInstanceState == null) {
Expand All @@ -119,8 +116,14 @@ private void setUpMap(Bundle savedInstanceState) {
.commit();
}

// Get the map
mapFragment.getMapAsync(this);
// Get the map asynchronously. We use reflection because the fragment type
// depends on the build flavor (SupportMapFragment or SupportNavigationFragment).
try {
mapFragment.getClass().getMethod("getMapAsync", OnMapReadyCallback.class)
.invoke(mapFragment, this);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.maps.android.utils.demo;

import androidx.fragment.app.Fragment;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.libraries.navigation.SupportNavigationFragment;

public class MapFragmentProvider {
public static Fragment getFragment(GoogleMapOptions options) {
if (options == null) {
return SupportNavigationFragment.newInstance();
} else {
return SupportNavigationFragment.newInstance(options);
}
}
}
23 changes: 23 additions & 0 deletions demo/src/standard/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2026 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.maps.android.utils.demo;

import androidx.fragment.app.Fragment;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.SupportMapFragment;

public class MapFragmentProvider {
public static Fragment getFragment(GoogleMapOptions options) {
if (options == null) {
return SupportMapFragment.newInstance();
} else {
return SupportMapFragment.newInstance(options);
}
}
}
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ compose-bom = "2026.02.00"
# --- Google Services (Maps) ---
# Versions for Google Play Services libraries essential for map functionality.
play-services-maps = "20.0.0"
navigation-sdk = "7.6.0"
desugar-jdk-libs = "2.1.5"

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

# --- Testing ---
# Tools for running implementation validation and user interface tests.
Expand Down
4 changes: 0 additions & 4 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
xmlns:tools="http://schemas.android.com/tools">
<!-- https://groups.google.com/group/adt-dev/browse_thread/thread/c059c0380998092b/6720093fb40fdaf9 -->
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
Expand Down
Loading