Skip to content
Open
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
8 changes: 0 additions & 8 deletions LOG.md

This file was deleted.

65 changes: 8 additions & 57 deletions Maps3DSamples/ApiDemos/java-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,7 @@
* limitations under the License.
*/

import java.util.Properties
import org.gradle.api.GradleException

// Check for secrets.properties file and valid API key before proceeding with build tasks.
val secretsFile = rootProject.file("secrets.properties")
val isCI = System.getenv("CI")?.toBoolean() ?: false

if (!isCI) {
val requestedTasks = gradle.startParameter.taskNames
if (requestedTasks.isEmpty() && !secretsFile.exists()) {
// It's likely an IDE sync if no tasks are specified, so just issue a warning.
println("Warning: secrets.properties not found. Gradle sync may succeed, but building/running the app will fail.")
} else if (requestedTasks.isNotEmpty()) {
val buildTaskKeywords = listOf("build", "install", "assemble")
val isBuildTask = requestedTasks.any { task ->
buildTaskKeywords.any { keyword ->
task.contains(keyword, ignoreCase = true)
}
}

val testTaskKeywords = listOf("test", "report", "lint")
val isTestTask = requestedTasks.any { task ->
testTaskKeywords.any { keyword ->
task.contains(keyword, ignoreCase = true)
}
}

val isDebugTask = requestedTasks.any { task ->
task.contains("Debug", ignoreCase = true) || task.contains("installAndLaunch", ignoreCase = true)
}

if (isBuildTask && !isTestTask && isDebugTask) {
val defaultsFile = rootProject.file("local.defaults.properties")
val requiredKeysMessage = if (defaultsFile.exists()) {
defaultsFile.readText()
} else {
"MAPS3D_API_KEY=<YOUR_API_KEY>"
}

if (!secretsFile.exists()) {
throw GradleException("secrets.properties file not found. Please create a 'secrets.properties' file in the root project directory with the following content:\n\n$requiredKeysMessage")
}

val secrets = Properties()
secretsFile.inputStream().use { secrets.load(it) }
val apiKey = secrets.getProperty("MAPS3D_API_KEY")

if (apiKey.isNullOrBlank() || !apiKey.matches(Regex("^AIza[a-zA-Z0-9_-]{35}$"))) {
throw GradleException("Invalid or missing MAPS3D_API_KEY in secrets.properties. Please provide a valid Google Maps API key (starts with 'AIza').")
}

if (secrets.getProperty("MAPS_API_KEY") != null) {
println("Warning: Found MAPS_API_KEY in secrets.properties. This project relies exclusively on MAPS3D_API_KEY.")
}
}
}
}
val isCI = rootProject.extra["isCI"] as? Boolean ?: false

plugins {
alias(libs.plugins.android.application)
Expand All @@ -92,6 +36,13 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

if (isCI) {
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"
manifestPlaceholders["PLACES_API_KEY"] = "DEFAULT_API_KEY"
}

buildConfigField("Boolean", "IS_CI", "${isCI}")
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public void onCreate() {
* incorrectly configured, and a RuntimeException is thrown.
*/
private void checkApiKey() {
if (BuildConfig.IS_CI) {
return;
}
try {
ApplicationInfo appInfo =
getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
Expand Down
66 changes: 8 additions & 58 deletions Maps3DSamples/ApiDemos/kotlin-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,7 @@
* limitations under the License.
*/

import org.gradle.api.GradleException
import java.io.File
import java.util.Properties

// Check for secrets.properties file and valid API key before proceeding with build tasks.
val secretsFile = rootProject.file("secrets.properties")
val isCI = System.getenv("CI")?.toBoolean() ?: false

if (!isCI) {
val requestedTasks = gradle.startParameter.taskNames
if (requestedTasks.isEmpty() && !secretsFile.exists()) {
// It's likely an IDE sync if no tasks are specified, so just issue a warning.
println("Warning: secrets.properties not found. Gradle sync may succeed, but building/running the app will fail.")
} else if (requestedTasks.isNotEmpty()) {
val buildTaskKeywords = listOf("build", "install", "assemble")
val isBuildTask = requestedTasks.any { task ->
buildTaskKeywords.any { keyword ->
task.contains(keyword, ignoreCase = true)
}
}

val testTaskKeywords = listOf("test", "report", "lint")
val isTestTask = requestedTasks.any { task ->
testTaskKeywords.any { keyword ->
task.contains(keyword, ignoreCase = true)
}
}

val isDebugTask = requestedTasks.any { task ->
task.contains("Debug", ignoreCase = true) || task.contains("installAndLaunch", ignoreCase = true)
}

if (isBuildTask && !isTestTask && isDebugTask) {
val defaultsFile = rootProject.file("local.defaults.properties")
val requiredKeysMessage = if (defaultsFile.exists()) {
defaultsFile.readText()
} else {
"MAPS3D_API_KEY=<YOUR_API_KEY>"
}

if (!secretsFile.exists()) {
throw GradleException("secrets.properties file not found. Please create a 'secrets.properties' file in the root project directory with the following content:\n\n$requiredKeysMessage")
}

val secrets = Properties()
secretsFile.inputStream().use { secrets.load(it) }
val apiKey = secrets.getProperty("MAPS3D_API_KEY")

if (apiKey.isNullOrBlank() || !apiKey.matches(Regex("^AIza[a-zA-Z0-9_-]{35}$"))) {
throw GradleException("Invalid or missing MAPS3D_API_KEY in secrets.properties. Please provide a valid Google Maps API key (starts with 'AIza').")
}

if (secrets.getProperty("MAPS_API_KEY") != null) {
println("Warning: Found MAPS_API_KEY in secrets.properties. This project relies exclusively on MAPS3D_API_KEY.")
}
}
}
}
val isCI = rootProject.extra["isCI"] as? Boolean ?: false

plugins {
alias(libs.plugins.android.application)
Expand All @@ -95,6 +38,13 @@ android {
versionName = "1.7.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

if (isCI) {
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"
manifestPlaceholders["PLACES_API_KEY"] = "DEFAULT_API_KEY"
}

buildConfigField("Boolean", "IS_CI", "${isCI}")
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class Maps3DKotlinApplication : Application() {
* incorrectly configured, and a RuntimeException is thrown.
*/
private fun checkApiKey() {
if (BuildConfig.IS_CI) {
return
}
try {
val appInfo =
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
Expand Down
63 changes: 6 additions & 57 deletions Maps3DSamples/advanced/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,7 @@
* limitations under the License.
*/

import java.util.Properties
import org.gradle.api.GradleException

// Check for secrets.properties file and valid API key before proceeding with build tasks.
val secretsFile = rootProject.file("secrets.properties")
val isCI = System.getenv("CI")?.toBoolean() ?: false

if (!isCI) {
val requestedTasks = gradle.startParameter.taskNames
if (requestedTasks.isEmpty() && !secretsFile.exists()) {
// It's likely an IDE sync if no tasks are specified, so just issue a warning.
println("Warning: secrets.properties not found. Gradle sync may succeed, but building/running the app will fail.")
} else if (requestedTasks.isNotEmpty()) {
val buildTaskKeywords = listOf("build", "install", "assemble")
val isBuildTask = requestedTasks.any { task ->
buildTaskKeywords.any { keyword ->
task.contains(keyword, ignoreCase = true)
}
}

val testTaskKeywords = listOf("test", "report", "lint")
val isTestTask = requestedTasks.any { task ->
testTaskKeywords.any { keyword ->
task.contains(keyword, ignoreCase = true)
}
}

val isDebugTask = requestedTasks.any { task ->
task.contains("Debug", ignoreCase = true) || task.contains("installAndLaunch", ignoreCase = true)
}

if (isBuildTask && !isTestTask && isDebugTask) {
val defaultsFile = rootProject.file("local.defaults.properties")
val requiredKeysMessage = if (defaultsFile.exists()) {
defaultsFile.readText()
} else {
"MAPS3D_API_KEY=<YOUR_API_KEY>"
}

if (!secretsFile.exists()) {
throw GradleException("secrets.properties file not found. Please create a 'secrets.properties' file in the root project directory with the following content:\n\n$requiredKeysMessage")
}

val secrets = Properties()
secretsFile.inputStream().use { secrets.load(it) }
val apiKey = secrets.getProperty("MAPS3D_API_KEY")

if (apiKey.isNullOrBlank() || !apiKey.matches(Regex("^AIza[a-zA-Z0-9_-]{35}$"))) {
throw GradleException("Invalid or missing MAPS3D_API_KEY in secrets.properties. Please provide a valid Google Maps API key (starts with 'AIza').")
}

if (secrets.getProperty("MAPS_API_KEY") != null) {
println("Warning: Found MAPS_API_KEY in secrets.properties. This project relies exclusively on MAPS3D_API_KEY.")
}
}
}
}
val isCI = rootProject.extra["isCI"] as? Boolean ?: false

plugins {
alias(libs.plugins.android.application)
Expand Down Expand Up @@ -98,6 +42,11 @@ android {
versionName = "1.7.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

if (isCI) {
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"
manifestPlaceholders["PLACES_API_KEY"] = "DEFAULT_API_KEY"
}
}

buildTypes {
Expand Down
9 changes: 9 additions & 0 deletions PlacesUIKit3D/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

val isCI = rootProject.extra["isCI"] as? Boolean ?: false

// The `plugins` block is where we apply Gradle plugins to this module.
// Plugins add new tasks and configurations to our build process.
plugins {
Expand Down Expand Up @@ -57,6 +59,13 @@ android {

// Specifies the instrumentation runner for running Android tests.
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

if (isCI) {
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"
manifestPlaceholders["PLACES_API_KEY"] = "DEFAULT_API_KEY"
}

buildConfigField("Boolean", "IS_CI", "${isCI}")
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Maps3DPlacesApplication : Application() {
}

private fun initializePlaces() {
if (BuildConfig.IS_CI) {
return
}
val apiKey = BuildConfig.PLACES_API_KEY

if (apiKey == null || apiKey.isBlank() || apiKey == "DEFAULT_API_KEY") {
Expand All @@ -58,6 +61,9 @@ class Maps3DPlacesApplication : Application() {
* incorrectly configured, and a RuntimeException is thrown.
*/
private fun checkApiKey() {
if (BuildConfig.IS_CI) {
return
}
try {
val appInfo =
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
Expand Down
72 changes: 72 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.
*/

import java.util.Properties

// Evaluate if we are in a CI environment
val isCI = System.getenv("CI")?.toBoolean() ?: false

// Share the isCI flag with all subprojects via Gradle's extra properties
extra["isCI"] = isCI

if (!isCI) {
val secretsFile = file("secrets.properties")
val requestedTasks = gradle.startParameter.taskNames

if (requestedTasks.isEmpty() && !secretsFile.exists()) {
// It's likely an IDE sync if no tasks are specified, so just issue a warning.
println("Warning: secrets.properties not found. Gradle sync may succeed, but building/running the app will fail.")
} else if (requestedTasks.isNotEmpty()) {
val buildTaskKeywords = setOf("build", "install", "assemble")
val testTaskKeywords = setOf("test", "report", "lint")

val isBuildTask = requestedTasks.any { name ->
buildTaskKeywords.any { kw -> name.contains(kw, ignoreCase = true) }
}
val isTestTask = requestedTasks.any { name ->
testTaskKeywords.any { kw -> name.contains(kw, ignoreCase = true) }
}
val isDebugTask = requestedTasks.any { task ->
task.contains("Debug", ignoreCase = true) || task.contains("installAndLaunch", ignoreCase = true)
}

if (isBuildTask && !isTestTask && isDebugTask) {
val defaultsFile = file("local.defaults.properties")
val requiredKeysMessage = if (defaultsFile.exists()) {
defaultsFile.readText()
} else {
"MAPS3D_API_KEY=<YOUR_API_KEY>\nPLACES_API_KEY=<YOUR_API_KEY>"
}

if (!secretsFile.exists()) {
throw GradleException("secrets.properties file not found. Please create a 'secrets.properties' file in the root project directory with the following content:\n\n$requiredKeysMessage")
}

val secrets = Properties()
secretsFile.inputStream().use { secrets.load(it) }
val mapsApiKey = secrets.getProperty("MAPS3D_API_KEY")
val placesApiKey = secrets.getProperty("PLACES_API_KEY")

if (mapsApiKey.isNullOrBlank() || !mapsApiKey.matches(Regex("^AIza[a-zA-Z0-9_-]{35}$"))) {
throw GradleException("Invalid or missing MAPS3D_API_KEY in secrets.properties. Please provide a valid Google Maps API key (starts with 'AIza').")
}

if (placesApiKey.isNullOrBlank() || !placesApiKey.matches(Regex("^AIza[a-zA-Z0-9_-]{35}$"))) {
throw GradleException("Invalid or missing PLACES_API_KEY in secrets.properties. Please provide a valid Google Places API key (starts with 'AIza').")
}
}
}
}
1 change: 1 addition & 0 deletions local.defaults.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
MAPS3D_API_KEY=DEFAULT_API_KEY
PLACES_API_KEY=DEFAULT_API_KEY
Loading
Loading