Skip to content

Commit e3e33d8

Browse files
dturnerGerrit Code Review
authored andcommitted
Merge "Add Firebase analytics. See go/nia-firebase-services." into main
2 parents 8c3fcef + 2a4d043 commit e3e33d8

File tree

44 files changed

+826
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+826
-40
lines changed

app/benchmark-rules.pro

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,16 @@
33
# Obsfuscation must be disabled for the build variant that generates Baseline Profile, otherwise
44
# wrong symbols would be generated. The generated Baseline Profile will be properly applied when generated
55
# without obfuscation and your app is being obfuscated.
6-
-dontobfuscate
6+
-dontobfuscate
7+
8+
# Please add these rules to your existing keep rules in order to suppress warnings.
9+
# This is generated automatically by the Android Gradle plugin.
10+
-dontwarn org.bouncycastle.jsse.BCSSLParameters
11+
-dontwarn org.bouncycastle.jsse.BCSSLSocket
12+
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
13+
-dontwarn org.conscrypt.Conscrypt$Version
14+
-dontwarn org.conscrypt.Conscrypt
15+
-dontwarn org.conscrypt.ConscryptHostnameVerifier
16+
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
17+
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
18+
-dontwarn org.openjsse.net.ssl.OpenJSSE

app/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import com.android.build.api.dsl.ManagedVirtualDevice
1919
plugins {
2020
id("nowinandroid.android.application")
2121
id("nowinandroid.android.application.compose")
22+
id("nowinandroid.android.application.flavors")
2223
id("nowinandroid.android.application.jacoco")
2324
id("nowinandroid.android.hilt")
24-
id("nowinandroid.firebase")
2525
id("jacoco")
26+
id("nowinandroid.android.application.firebase")
2627
}
2728

2829
android {
@@ -101,6 +102,7 @@ dependencies {
101102
implementation(project(":core:designsystem"))
102103
implementation(project(":core:data"))
103104
implementation(project(":core:model"))
105+
implementation(project(":core:analytics"))
104106

105107
implementation(project(":sync:work"))
106108

app/google-services.json

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"project_info": {
3+
"project_number": "YourProjectId",
4+
"project_id": "abc",
5+
"storage_bucket": "abc"
6+
},
7+
"client": [
8+
{
9+
"client_info": {
10+
"mobilesdk_app_id": "Your:App:Id",
11+
"android_client_info": {
12+
"package_name": "com.google.samples.apps.nowinandroid"
13+
}
14+
},
15+
"oauth_client": [],
16+
"api_key": [
17+
{
18+
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
19+
}
20+
],
21+
"services": {
22+
"appinvite_service": {
23+
"other_platform_oauth_client": []
24+
}
25+
}
26+
},
27+
{
28+
"client_info": {
29+
"mobilesdk_app_id": "Your:App:Id",
30+
"android_client_info": {
31+
"package_name": "com.google.samples.apps.nowinandroid.demo.debug"
32+
}
33+
},
34+
"oauth_client": [],
35+
"api_key": [
36+
{
37+
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
38+
}
39+
],
40+
"services": {
41+
"appinvite_service": {
42+
"other_platform_oauth_client": []
43+
}
44+
}
45+
},
46+
{
47+
"client_info": {
48+
"mobilesdk_app_id": "Your:App:Id",
49+
"android_client_info": {
50+
"package_name": "com.google.samples.apps.nowinandroid.demo.benchmark"
51+
}
52+
},
53+
"oauth_client": [],
54+
"api_key": [
55+
{
56+
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
57+
}
58+
],
59+
"services": {
60+
"appinvite_service": {
61+
"other_platform_oauth_client": []
62+
}
63+
}
64+
},
65+
{
66+
"client_info": {
67+
"mobilesdk_app_id": "Your:App:Id",
68+
"android_client_info": {
69+
"package_name": "com.google.samples.apps.nowinandroid.benchmark"
70+
}
71+
},
72+
"oauth_client": [],
73+
"api_key": [
74+
{
75+
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
76+
}
77+
],
78+
"services": {
79+
"appinvite_service": {
80+
"other_platform_oauth_client": []
81+
}
82+
}
83+
},
84+
{
85+
"client_info": {
86+
"mobilesdk_app_id": "Your:App:Id",
87+
"android_client_info": {
88+
"package_name": "com.google.samples.apps.nowinandroid.debug"
89+
}
90+
},
91+
"oauth_client": [],
92+
"api_key": [
93+
{
94+
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
95+
}
96+
],
97+
"services": {
98+
"appinvite_service": {
99+
"other_platform_oauth_client": []
100+
}
101+
}
102+
},
103+
{
104+
"client_info": {
105+
"mobilesdk_app_id": "Your:App:Id",
106+
"android_client_info": {
107+
"package_name": "com.google.samples.apps.nowinandroid.demo"
108+
}
109+
},
110+
"oauth_client": [],
111+
"api_key": [
112+
{
113+
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
114+
}
115+
],
116+
"services": {
117+
"appinvite_service": {
118+
"other_platform_oauth_client": []
119+
}
120+
}
121+
}
122+
],
123+
124+
"configuration_version": "1"
125+
}

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
<category android:name="android.intent.category.LAUNCHER" />
4040
</intent-filter>
4141
</activity>
42+
43+
<!-- Disable Firebase analytics by default. This setting is overwritten for the `prod`
44+
flavor -->
45+
<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />
4246
</application>
4347

4448
</manifest>

app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import androidx.compose.foundation.isSystemInDarkTheme
2424
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
2525
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
2626
import androidx.compose.runtime.Composable
27+
import androidx.compose.runtime.CompositionLocalProvider
2728
import androidx.compose.runtime.DisposableEffect
2829
import androidx.compose.runtime.getValue
2930
import androidx.compose.runtime.mutableStateOf
@@ -37,6 +38,8 @@ import androidx.metrics.performance.JankStats
3738
import com.google.accompanist.systemuicontroller.rememberSystemUiController
3839
import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading
3940
import com.google.samples.apps.nowinandroid.MainActivityUiState.Success
41+
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
42+
import com.google.samples.apps.nowinandroid.core.analytics.LocalAnalyticsHelper
4043
import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor
4144
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
4245
import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
@@ -61,6 +64,9 @@ class MainActivity : ComponentActivity() {
6164
@Inject
6265
lateinit var networkMonitor: NetworkMonitor
6366

67+
@Inject
68+
lateinit var analyticsHelper: AnalyticsHelper
69+
6470
val viewModel: MainActivityViewModel by viewModels()
6571

6672
override fun onCreate(savedInstanceState: Bundle?) {
@@ -104,15 +110,17 @@ class MainActivity : ComponentActivity() {
104110
onDispose {}
105111
}
106112

107-
NiaTheme(
108-
darkTheme = darkTheme,
109-
androidTheme = shouldUseAndroidTheme(uiState),
110-
disableDynamicTheming = shouldDisableDynamicTheming(uiState),
111-
) {
112-
NiaApp(
113-
networkMonitor = networkMonitor,
114-
windowSizeClass = calculateWindowSizeClass(this),
115-
)
113+
CompositionLocalProvider(LocalAnalyticsHelper provides analyticsHelper) {
114+
NiaTheme(
115+
darkTheme = darkTheme,
116+
androidTheme = shouldUseAndroidTheme(uiState),
117+
disableDynamicTheming = shouldDisableDynamicTheming(uiState),
118+
) {
119+
NiaApp(
120+
networkMonitor = networkMonitor,
121+
windowSizeClass = calculateWindowSizeClass(this),
122+
)
123+
}
116124
}
117125
}
118126
}

app/src/prod/AndroidManifest.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2023 The Android Open Source Project
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+
http://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+
<application>
20+
<!-- Enable Firebase analytics for `prod` builds -->
21+
<meta-data
22+
tools:replace="android:value"
23+
android:name="firebase_analytics_collection_deactivated"
24+
android:value="false" />
25+
</application>
26+
</manifest>

build-logic/convention/build.gradle.kts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ java {
2828
dependencies {
2929
compileOnly(libs.android.gradlePlugin)
3030
compileOnly(libs.kotlin.gradlePlugin)
31+
compileOnly(libs.firebase.performance.gradle)
32+
compileOnly(libs.firebase.crashlytics.gradle)
3133
}
3234

3335
gradlePlugin {
@@ -68,9 +70,14 @@ gradlePlugin {
6870
id = "nowinandroid.android.hilt"
6971
implementationClass = "AndroidHiltConventionPlugin"
7072
}
71-
register("firebase") {
72-
id = "nowinandroid.firebase"
73-
implementationClass = "FirebaseConventionPlugin"
73+
register("androidFirebase") {
74+
id = "nowinandroid.android.application.firebase"
75+
implementationClass = "AndroidApplicationFirebaseConventionPlugin"
7476
}
77+
register("androidFlavors") {
78+
id = "nowinandroid.android.application.flavors"
79+
implementationClass = "AndroidApplicationFlavorsConventionPlugin"
80+
}
81+
7582
}
7683
}

build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
1817
import com.android.build.api.dsl.ApplicationExtension
19-
import com.google.samples.apps.nowinandroid.configureFlavors
18+
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
2019
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
2120
import com.google.samples.apps.nowinandroid.configurePrintApksTask
2221
import org.gradle.api.Plugin
@@ -34,7 +33,6 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
3433
extensions.configure<ApplicationExtension> {
3534
configureKotlinAndroid(this)
3635
defaultConfig.targetSdk = 33
37-
configureFlavors(this)
3836
}
3937
extensions.configure<ApplicationAndroidComponentsExtension> {
4038
configurePrintApksTask(this)

build-logic/convention/src/main/kotlin/FirebaseConventionPlugin.kt renamed to build-logic/convention/src/main/kotlin/AndroidApplicationFirebaseConventionPlugin.kt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
18+
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
1719
import org.gradle.api.Plugin
1820
import org.gradle.api.Project
1921
import org.gradle.api.artifacts.VersionCatalogsExtension
22+
import org.gradle.kotlin.dsl.configure
2023
import org.gradle.kotlin.dsl.dependencies
2124
import org.gradle.kotlin.dsl.getByType
2225

23-
class FirebaseConventionPlugin : Plugin<Project> {
26+
class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> {
2427
override fun apply(target: Project) {
25-
// Only apply this to Google Play releases.
26-
if (!target.hasProperty("use-google-services"))
27-
return
2828
with(target) {
2929
with(pluginManager) {
3030
apply("com.google.gms.google-services")
@@ -35,10 +35,23 @@ class FirebaseConventionPlugin : Plugin<Project> {
3535
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
3636
dependencies {
3737
val bom = libs.findLibrary("firebase-bom").get()
38-
add("releaseImplementation", platform(bom))
39-
"releaseImplementation"(libs.findLibrary("firebase.analytics").get())
40-
"releaseImplementation"(libs.findLibrary("firebase.crashlytics").get())
41-
"releaseImplementation"(libs.findLibrary("firebase.performance").get())
38+
add("implementation", platform(bom))
39+
"implementation"(libs.findLibrary("firebase.analytics").get())
40+
"implementation"(libs.findLibrary("firebase.performance").get())
41+
"implementation"(libs.findLibrary("firebase.crashlytics").get())
42+
}
43+
44+
extensions.configure<ApplicationAndroidComponentsExtension> {
45+
finalizeDsl {
46+
it.buildTypes.forEach { buildType ->
47+
// Disable the Crashlytics mapping file upload. This feature should only be
48+
// enabled if a Firebase backend is available and configured in
49+
// google-services.json.
50+
buildType.configure<CrashlyticsExtension> {
51+
mappingFileUploadEnabled = false
52+
}
53+
}
54+
}
4255
}
4356
}
4457
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2023 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import com.android.build.api.dsl.ApplicationExtension
18+
import com.google.samples.apps.nowinandroid.configureFlavors
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.kotlin.dsl.configure
22+
23+
class AndroidApplicationFlavorsConventionPlugin : Plugin<Project> {
24+
override fun apply(target: Project) {
25+
with(target) {
26+
extensions.configure<ApplicationExtension> {
27+
configureFlavors(this)
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)