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: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jobs:
distribution: 'adopt'
java-version: '21'
- name: Build ApiDemos
run: cd Maps3DSamples/ApiDemos && ./gradlew buildDebugPreBundle
run: ./gradlew :Maps3DSamples:ApiDemos:java-app:assembleDebug :Maps3DSamples:ApiDemos:kotlin-app:assembleDebug
- name: Run ApiDemos Unit Tests
run: ./gradlew :Maps3DSamples:ApiDemos:java-app:testDebugUnitTest :Maps3DSamples:ApiDemos:kotlin-app:testDebugUnitTest

build-advanced:
runs-on: ubuntu-latest
Expand All @@ -52,4 +54,6 @@ jobs:
distribution: 'adopt'
java-version: '21'
- name: Build advanced
run: cd Maps3DSamples/advanced && ./gradlew buildDebugPreBundle
run: ./gradlew :Maps3DSamples:advanced:app:assembleDebug
- name: Run advanced Unit Tests
run: ./gradlew :Maps3DSamples:advanced:app:testDebugUnitTest
8 changes: 0 additions & 8 deletions LOG.md

This file was deleted.

62 changes: 8 additions & 54 deletions Maps3DSamples/ApiDemos/java-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +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').")
}
}
}
}
val isCI = rootProject.extra["isCI"] as? Boolean ?: false

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

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"

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
63 changes: 8 additions & 55 deletions Maps3DSamples/ApiDemos/kotlin-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +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').")
}
}
}
}
val isCI = rootProject.extra["isCI"] as? Boolean ?: false

plugins {
alias(libs.plugins.android.application)
Expand All @@ -91,7 +38,13 @@ android {
versionName = "1.8.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"

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: 8 additions & 55 deletions Maps3DSamples/advanced/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +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').")
}
}
}
}
val isCI = rootProject.extra["isCI"] as? Boolean ?: false

plugins {
alias(libs.plugins.android.application)
Expand Down Expand Up @@ -94,7 +42,12 @@ android {
versionName = "1.8.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"

if (isCI) {
manifestPlaceholders["MAPS3D_API_KEY"] = "DEFAULT_API_KEY"
manifestPlaceholders["PLACES_API_KEY"] = "DEFAULT_API_KEY"
}
buildConfigField("Boolean", "IS_CI", "${isCI}")
}

buildTypes {
Expand Down Expand Up @@ -178,4 +131,4 @@ tasks.register<Exec>("installAndLaunch") {
commandLine("adb", "shell", "am", "start", "-n", "com.example.advancedmaps3dsamples/.MainActivity")
}

tasks.register("prepareKotlinBuildScriptModel"){}
tasks.register("prepareKotlinBuildScriptModel"){}
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
Loading
Loading