Skip to content

Commit 0a02c06

Browse files
authored
Merge pull request #591 from android/feb13-merge
All changes from 0.0.5 release (merge from internal repo)
2 parents 6799876 + 36eeb19 commit 0a02c06

File tree

49 files changed

+883
-71
lines changed

Some content is hidden

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

49 files changed

+883
-71
lines changed

.google/BUILDME

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file can be used to trigger an internal build by changing the number below
2+
3

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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ 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")
2425
id("jacoco")
25-
id("nowinandroid.firebase-perf")
26+
id("nowinandroid.android.application.firebase")
2627
}
2728

2829
android {
2930
defaultConfig {
3031
applicationId = "com.google.samples.apps.nowinandroid"
31-
versionCode = 4
32-
versionName = "0.0.4" // X.Y.Z; X = Major, Y = minor, Z = Patch level
32+
versionCode = 5
33+
versionName = "0.0.5" // X.Y.Z; X = Major, Y = minor, Z = Patch level
3334

3435
// Custom test runner to set up Hilt dependency graph
3536
testInstrumentationRunner = "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner"
@@ -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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919

2020
<uses-permission android:name="android.permission.INTERNET" />
2121

22+
<!--
23+
Firebase automatically adds the AD_ID permission, even though we don't use it. If you use this
24+
permission you must declare how you're using it to Google Play, otherwise the app will be
25+
rejected when publishing it. To avoid this we remove the permission entirely.
26+
-->
27+
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
28+
2229
<application
2330
android:name=".NiaApplication"
2431
android:allowBackup="true"
@@ -39,6 +46,12 @@
3946
<category android:name="android.intent.category.LAUNCHER" />
4047
</intent-filter>
4148
</activity>
49+
50+
<!-- Disable Firebase analytics by default. This setting is overwritten for the `prod`
51+
flavor -->
52+
<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />
53+
<!-- Disable collection of AD_ID for all build variants -->
54+
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="false" />
4255
</application>
4356

4457
</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: 9 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
compileOnly(libs.ksp.gradlePlugin)
3234
}
3335

@@ -73,9 +75,13 @@ gradlePlugin {
7375
id = "nowinandroid.android.room"
7476
implementationClass = "AndroidRoomConventionPlugin"
7577
}
76-
register("firebase-perf") {
77-
id = "nowinandroid.firebase-perf"
78-
implementationClass = "FirebasePerfConventionPlugin"
78+
register("androidFirebase") {
79+
id = "nowinandroid.android.application.firebase"
80+
implementationClass = "AndroidApplicationFirebaseConventionPlugin"
81+
}
82+
register("androidFlavors") {
83+
id = "nowinandroid.android.application.flavors"
84+
implementationClass = "AndroidApplicationFlavorsConventionPlugin"
7985
}
8086
}
8187
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
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
2018
import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
19+
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
2120
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
2221
import com.google.samples.apps.nowinandroid.configurePrintApksTask
2322
import org.gradle.api.Plugin
@@ -35,7 +34,6 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
3534
extensions.configure<ApplicationExtension> {
3635
configureKotlinAndroid(this)
3736
defaultConfig.targetSdk = 33
38-
configureFlavors(this)
3937
configureGradleManagedDevices(this)
4038
}
4139
extensions.configure<ApplicationAndroidComponentsExtension> {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2022 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.variant.ApplicationAndroidComponentsExtension
18+
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.api.artifacts.VersionCatalogsExtension
22+
import org.gradle.kotlin.dsl.configure
23+
import org.gradle.kotlin.dsl.dependencies
24+
import org.gradle.kotlin.dsl.getByType
25+
26+
class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> {
27+
override fun apply(target: Project) {
28+
with(target) {
29+
with(pluginManager) {
30+
apply("com.google.gms.google-services")
31+
apply("com.google.firebase.firebase-perf")
32+
apply("com.google.firebase.crashlytics")
33+
}
34+
35+
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
36+
dependencies {
37+
val bom = libs.findLibrary("firebase-bom").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+
}
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)