Skip to content

Commit 1b9b56b

Browse files
committed
integrate startup-runtime lib
1 parent e6ead25 commit 1b9b56b

20 files changed

Lines changed: 312 additions & 2 deletions

File tree

ApiDemos/project/common-ui/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ android {
6565
}
6666

6767
dependencies {
68-
68+
api(project(":library"))
6969
implementation(libs.core.ktx)
7070
implementation(libs.appcompat)
7171
implementation(libs.material)

FireMarkers/app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ android {
9595
}
9696

9797
dependencies {
98+
api(project(":library"))
9899
// ---------------------------------------------------------------------------------------------
99100
// AndroidX & Jetpack
100101
//

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ To run instrumentation tests on a connected device or emulator, use:
6464
Alternatively, use the `gradlew build` command to build the project directly or download an APK
6565
under [releases](https://github.com/googlemaps/android-samples/releases).
6666

67+
## Internal usage attribution ID
68+
69+
This library calls the `addInternalUsageAttributionId` method, which helps Google understand which libraries and samples are helpful to developers and is optional. Instructions for opting out of the identifier are provided below.
70+
71+
If you wish to disable this, you can do so by removing the initializer in your `AndroidManifest.xml` using the `tools:node="remove"` attribute:
72+
73+
```xml
74+
<provider
75+
android:name="androidx.startup.InitializationProvider"
76+
android:authorities="${applicationId}.androidx-startup"
77+
android:exported="false"
78+
tools:node="merge">
79+
<meta-data
80+
android:name="com.example.library.utils.attribution.AttributionIdInitializer"
81+
tools:node="remove" />
82+
</provider>
83+
```
84+
6785
## Contributing
6886

6987
Contributions are welcome and encouraged! If you'd like to contribute, send us a [pull request] and refer to our [code of conduct] and [contributing guide].

WearOS/Wearable/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ android {
5353

5454
// [START maps_wear_os_dependencies]
5555
dependencies {
56+
api(project(":library"))
5657
// [START_EXCLUDE]
5758
implementation(libs.core.ktx)
5859
implementation(platform(libs.kotlin.bom))

gradle/libs.versions.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ robolectric = "4.16.1"
5858
truth = "1.4.5"
5959
turbine = "1.2.1"
6060
uiautomator = "2.3.0"
61+
mockk = "1.14.11"
6162

6263
# Firebase
6364
firebaseBom = "34.8.0"
@@ -67,12 +68,16 @@ firebaseDatabase = "22.0.1"
6768
easypermissions = "3.0.0"
6869
volley = "1.2.1"
6970

71+
#Tracker lib
72+
startup-runtime = "1.2.0"
73+
7074
[libraries]
7175
# Kotlin
7276
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
7377
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
7478
kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
7579
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
80+
startup-runtime = { module = "androidx.startup:startup-runtime", version.ref = "startup-runtime" }
7681

7782
# AndroidX
7883
activity = { module = "androidx.activity:activity", version.ref = "activity" }
@@ -130,6 +135,7 @@ turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" }
130135
ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" }
131136
ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "compose" }
132137
uiautomator = { group = "androidx.test.uiautomator", name = "uiautomator", version.ref = "uiautomator" }
138+
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
133139

134140
# Firebase
135141
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebaseBom" }

library/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

library/build.gradle.kts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
3+
/*
4+
* Copyright 2026 Google LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
plugins {
20+
alias(libs.plugins.android.library)
21+
alias(libs.plugins.kotlin.android)
22+
}
23+
24+
android {
25+
namespace = "com.example.library"
26+
compileSdk = libs.versions.compileSdk.get().toInt()
27+
28+
defaultConfig {
29+
minSdk = libs.versions.minSdk.get().toInt()
30+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
31+
consumerProguardFiles("consumer-rules.pro")
32+
}
33+
buildTypes {
34+
release {
35+
isMinifyEnabled = false
36+
proguardFiles(
37+
getDefaultProguardFile("proguard-android-optimize.txt"),
38+
"proguard-rules.pro"
39+
)
40+
}
41+
}
42+
lint {
43+
abortOnError = false
44+
}
45+
compileOptions {
46+
sourceCompatibility = JavaVersion.VERSION_17
47+
targetCompatibility = JavaVersion.VERSION_17
48+
}
49+
lint {
50+
disable += setOf("MissingInflatedId", "OnClick")
51+
sarifOutput = layout.buildDirectory.file("reports/lint-results-debug.sarif").get().asFile
52+
}
53+
kotlin {
54+
compilerOptions {
55+
jvmTarget.set(JvmTarget.JVM_17)
56+
javaParameters.set(true)
57+
}
58+
}
59+
}
60+
61+
dependencies {
62+
implementation(libs.appcompat)
63+
implementation(libs.core.ktx)
64+
implementation(libs.material)
65+
implementation(libs.startup.runtime)
66+
implementation(libs.play.services.maps)
67+
testImplementation(libs.junit)
68+
testImplementation(libs.robolectric)
69+
testImplementation(libs.mockk)
70+
testImplementation(libs.espresso.core)
71+
}
72+
73+
74+
abstract class GenerateArtifactIdTask : DefaultTask() {
75+
@get:OutputDirectory
76+
abstract val outputDir: DirectoryProperty
77+
78+
@get:Input
79+
abstract val version: Property<String>
80+
81+
@TaskAction
82+
fun generate() {
83+
val dir = outputDir.get().asFile
84+
val packageName = "com.example.library.utils.meta"
85+
val packagePath = packageName.replace('.', '/')
86+
val outputFile = File(dir, "$packagePath/ArtifactId.kt")
87+
outputFile.parentFile.mkdirs()
88+
val attributionId = "gmp_git_androidsamples_v${version.get()}"
89+
outputFile.writeText(
90+
"""
91+
package $packageName
92+
93+
/**
94+
* Automatically generated object containing the library's attribution ID.
95+
* This is used to track library usage for analytics.
96+
*/
97+
public object AttributionId {
98+
public const val VALUE: String = "$attributionId"
99+
}
100+
""".trimIndent()
101+
)
102+
}
103+
}
104+
105+
val generateArtifactIdFile = tasks.register<GenerateArtifactIdTask>("generateArtifactIdFile") {
106+
outputDir.set(layout.buildDirectory.dir("generated/source/artifactId"))
107+
version.set(libs.versions.versionName.get())
108+
}
109+
110+
androidComponents {
111+
onVariants { variant ->
112+
variant.sources.java?.addGeneratedSourceDirectory(
113+
generateArtifactIdFile,
114+
GenerateArtifactIdTask::outputDir
115+
)
116+
}
117+
}

library/consumer-rules.pro

Whitespace-only changes.

library/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
https://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+
xmlns:tools="http://schemas.android.com/tools">
19+
20+
21+
<application>
22+
<provider
23+
android:name="androidx.startup.InitializationProvider"
24+
android:authorities="${applicationId}.androidx-startup"
25+
android:exported="false"
26+
tools:node="merge">
27+
28+
<meta-data
29+
android:name="com.example.library.utils.attribution.AttributionIdInitializer"
30+
android:value="androidx.startup" />
31+
</provider>
32+
</application>
33+
34+
</manifest>

0 commit comments

Comments
 (0)