-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
193 lines (170 loc) · 6.65 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
193 lines (170 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
* 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 org.gradle.api.GradleException
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
id("com.android.application")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
id("org.jetbrains.kotlin.plugin.serialization") version libs.versions.kotlin.get()
alias(libs.plugins.compose.compiler)
}
val secretsFile = rootProject.file("secrets.properties")
if (!secretsFile.exists()) {
val taskNames = gradle.startParameter.taskNames
// 1. Allow IDE Sync (which runs with empty tasks)
if (taskNames.isEmpty()) {
println("⚠️ Warning: secrets.properties missing. IDE sync will succeed, but builds will fail.")
} else {
// 2. Normalize task names to handle ":demo:assembleDebug" -> "assembleDebug"
val simpleTaskNames = taskNames.map { it.substringAfterLast(":") }
// 3. Identify if the user is explicitly asking for an app build
val isExplicitBuild = simpleTaskNames.any {
it == "build" ||
it.startsWith("assemble") ||
it.startsWith("install") ||
it.startsWith("bundle")
}
// 4. Identify if the user is running tests/lint
// (We check for "Test" to allow tasks like 'assembleAndroidTest' to proceed if desired)
val isTestOrLint = simpleTaskNames.any {
val lower = it.lowercase()
lower.contains("test") || lower.contains("lint")
}
// 5. Fail ONLY if it's a build task that isn't also a test task
if (isExplicitBuild && !isTestOrLint) {
throw GradleException("Build Blocked: 'secrets.properties' is missing.\n\n" +
"🛑 To build the demo app, you must create the 'secrets.properties' file in the root directory:\n\n" +
" MAPS_API_KEY=AIza...\n" +
" PLACES_API_KEY=AIza... # Only needed for certain demos (e.g., HeatmapsPlacesDemoActivity.java)\n" +
" MAP_ID=...\n\n" +
"Or run unit tests only: ./gradlew test")
} else {
println("⚠️ Warning: secrets.properties missing. Building/Running the demo app will fail, but testing is allowed.")
}
}
}
android {
lint {
sarifOutput = layout.buildDirectory.file("reports/lint-results.sarif").get().asFile
}
defaultConfig {
compileSdk = libs.versions.compileSdk.get().toInt()
applicationId = "com.google.maps.android.utils.demo"
minSdk = libs.versions.minimumSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
buildFeatures {
viewBinding = true
compose = true
buildConfig = true
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
jvmToolchain(17)
}
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+
}
}
}
configurations.all {
resolutionStrategy {
force(libs.kotlinx.coroutines.core)
force(libs.kotlinx.coroutines.android)
force(libs.kotlinx.serialization.json)
}
exclude(group = "org.chromium.net", module = "cronet-fallback")
if (name.contains("navigation", ignoreCase = true)) {
exclude(group = "com.google.android.gms", module = "play-services-maps")
}
}
// [START maps_android_utils_install_snippet]
dependencies {
coreLibraryDesugaring(libs.desugar.jdk.libs)
// [START_EXCLUDE silent]
// [START_EXCLUDE silent]
val modules = listOf(":clustering", ":heatmaps", ":ui", ":data")
modules.forEach { moduleName ->
"standardImplementation"(project(moduleName))
"navigationImplementation"(project(moduleName))
}
"navigationImplementation"(libs.navigation.sdk)
implementation(libs.appcompat)
implementation(libs.lifecycle.extensions)
implementation(libs.lifecycle.viewmodel.ktx)
implementation(libs.kotlin.stdlib.jdk8)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.material)
implementation(libs.core.ktx)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.kotlinx.serialization.json)
testImplementation(libs.junit)
testImplementation(libs.truth)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
androidTestImplementation(libs.truth)
implementation(project(":visual-testing"))
implementation(libs.uiautomator)
implementation(platform(libs.compose.bom))
implementation(libs.activity.compose)
implementation(libs.ui)
implementation(libs.ui.graphics)
implementation(libs.ui.tooling.preview)
implementation(libs.material3)
implementation(libs.material.icons.core)
debugImplementation(libs.ui.tooling)
// [END_EXCLUDE]
}
// [END maps_android_utils_install_snippet]
secrets {
// To add your Maps API key to this project:
// 1. Create a file ./secrets.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
defaultPropertiesFileName ="local.defaults.properties"
propertiesFileName = "secrets.properties"
}