Skip to content

Commit 8d89a89

Browse files
committed
Merge remote-tracking branch 'origin/main' into move-android-instrumented-test
2 parents d17f3b1 + 84e2714 commit 8d89a89

File tree

87 files changed

+445
-480
lines changed

Some content is hidden

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

87 files changed

+445
-480
lines changed

.github/workflows/Build.yaml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,40 @@ jobs:
4545
- name: Check spotless
4646
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
4747

48+
- name: Check Dependency Guard
49+
id: dependencyguard_verify
50+
continue-on-error: true
51+
run: ./gradlew dependencyGuard
52+
53+
- name: Prevent updating Dependency Guard baselines if this is a fork
54+
id: checkfork_dependencyguard
55+
continue-on-error: false
56+
if: steps.dependencyguard_verify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository
57+
run: |
58+
echo "::error::Dependency Guard failed, please update baselines with: ./gradlew dependencyGuardBaseline" && exit 1
59+
60+
# Runs if previous job failed
61+
- name: Generate new Dependency Guard baselines if verification failed and it's a PR
62+
id: dependencyguard_baseline
63+
if: steps.dependencyguard_verify.outcome == 'failure' && github.event_name == 'pull_request'
64+
run: |
65+
./gradlew dependencyGuardBaseline
66+
67+
- name: Push new Dependency Guard baselines if available
68+
uses: stefanzweifel/git-auto-commit-action@v5
69+
if: steps.dependencyguard_baseline.outcome == 'success'
70+
with:
71+
file_pattern: '**/dependencies/*.txt'
72+
disable_globbing: true
73+
commit_message: "🤖 Updates baselines for Dependency Guard"
74+
4875
- name: Run all local screenshot tests (Roborazzi)
4976
id: screenshotsverify
5077
continue-on-error: true
5178
run: ./gradlew verifyRoborazziDemoDebug
5279

5380
- name: Prevent pushing new screenshots if this is a fork
54-
id: checkfork
81+
id: checkfork_screenshots
5582
continue-on-error: false
5683
if: steps.screenshotsverify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository
5784
run: |
@@ -82,13 +109,9 @@ jobs:
82109
- name: Build all build type and flavor permutations
83110
run: ./gradlew :app:assemble :benchmarks:assemble
84111
-x pixel6Api33ProdNonMinifiedReleaseAndroidTest
85-
-x pixel6Api33ProdNonMinifiedBenchmarkAndroidTest
86112
-x pixel6Api33DemoNonMinifiedReleaseAndroidTest
87-
-x pixel6Api33DemoNonMinifiedBenchmarkAndroidTest
88113
-x collectDemoNonMinifiedReleaseBaselineProfile
89-
-x collectDemoNonMinifiedBenchmarkBaselineProfile
90114
-x collectProdNonMinifiedReleaseBaselineProfile
91-
-x collectProdNonMinifiedBenchmarkBaselineProfile
92115

93116
- name: Upload build outputs (APKs)
94117
uses: actions/upload-artifact@v4
@@ -117,13 +140,31 @@ jobs:
117140
run: ./gradlew :app:checkProdReleaseBadging
118141

119142
androidTest:
120-
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
143+
runs-on: ubuntu-latest
121144
timeout-minutes: 55
122145
strategy:
123146
matrix:
124147
api-level: [26, 30]
125148

126149
steps:
150+
- name: Delete unnecessary tools 🔧
151+
uses: jlumbroso/[email protected]
152+
with:
153+
android: false # Don't remove Android tools
154+
tool-cache: true # Remove image tool cache - rm -rf "$AGENT_TOOLSDIRECTORY"
155+
dotnet: true # rm -rf /usr/share/dotnet
156+
haskell: true # rm -rf /opt/ghc...
157+
swap-storage: true # rm -f /mnt/swapfile (4GiB)
158+
docker-images: false # Takes 16s, enable if needed in the future
159+
large-packages: false # includes google-cloud-sdk and it's slow
160+
161+
- name: Enable KVM group perms
162+
run: |
163+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
164+
sudo udevadm control --reload-rules
165+
sudo udevadm trigger --name-match=kvm
166+
ls /dev/kvm
167+
127168
- name: Checkout
128169
uses: actions/checkout@v4
129170

.github/workflows/Release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ on:
77

88
jobs:
99
build:
10-
runs-on: macos-latest
10+
runs-on: ubuntu-latest
1111
timeout-minutes: 120
1212

1313
steps:
14+
- name: Enable KVM group perms
15+
run: |
16+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
17+
sudo udevadm control --reload-rules
18+
sudo udevadm trigger --name-match=kvm
19+
ls /dev/kvm
20+
1421
- name: Checkout
1522
uses: actions/checkout@v4
1623

app-nia-catalog/dependencies/releaseRuntimeClasspath.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ androidx.profileinstaller:profileinstaller:1.3.1
7070
androidx.savedstate:savedstate-ktx:1.2.1
7171
androidx.savedstate:savedstate:1.2.1
7272
androidx.startup:startup-runtime:1.1.1
73-
androidx.tracing:tracing:1.0.0
73+
androidx.tracing:tracing-ktx:1.3.0-alpha02
74+
androidx.tracing:tracing:1.3.0-alpha02
7475
androidx.vectordrawable:vectordrawable-animated:1.1.0
7576
androidx.vectordrawable:vectordrawable:1.1.0
7677
androidx.versionedparcelable:versionedparcelable:1.1.1

app/build.gradle.kts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,6 @@ android {
5757
// Ensure Baseline Profile is fresh for release builds.
5858
baselineProfile.automaticGenerationDuringBuild = true
5959
}
60-
create("benchmark") {
61-
// Enable all the optimizations from release build through initWith(release).
62-
initWith(release)
63-
matchingFallbacks.add("release")
64-
// Debug key signing is available to everyone.
65-
signingConfig = signingConfigs.getByName("debug")
66-
// Only use benchmark proguard rules
67-
proguardFiles("benchmark-rules.pro")
68-
isMinifyEnabled = true
69-
applicationIdSuffix = NiaBuildType.BENCHMARK.applicationIdSuffix
70-
}
7160
}
7261

7362
packaging {

app/dependencies/prodReleaseRuntimeClasspath.txt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,20 @@ androidx.hilt:hilt-navigation:1.0.0
7171
androidx.hilt:hilt-work:1.1.0
7272
androidx.interpolator:interpolator:1.0.0
7373
androidx.legacy:legacy-support-core-utils:1.0.0
74-
androidx.lifecycle:lifecycle-common-java8:2.6.2
75-
androidx.lifecycle:lifecycle-common:2.6.2
76-
androidx.lifecycle:lifecycle-livedata-core:2.6.2
77-
androidx.lifecycle:lifecycle-livedata:2.6.2
78-
androidx.lifecycle:lifecycle-process:2.6.2
79-
androidx.lifecycle:lifecycle-runtime-compose:2.6.2
80-
androidx.lifecycle:lifecycle-runtime-ktx:2.6.2
81-
androidx.lifecycle:lifecycle-runtime:2.6.2
82-
androidx.lifecycle:lifecycle-service:2.6.2
83-
androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2
84-
androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2
85-
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2
86-
androidx.lifecycle:lifecycle-viewmodel:2.6.2
74+
androidx.lifecycle:lifecycle-common-java8:2.7.0
75+
androidx.lifecycle:lifecycle-common:2.7.0
76+
androidx.lifecycle:lifecycle-livedata-core-ktx:2.7.0
77+
androidx.lifecycle:lifecycle-livedata-core:2.7.0
78+
androidx.lifecycle:lifecycle-livedata:2.7.0
79+
androidx.lifecycle:lifecycle-process:2.7.0
80+
androidx.lifecycle:lifecycle-runtime-compose:2.7.0
81+
androidx.lifecycle:lifecycle-runtime-ktx:2.7.0
82+
androidx.lifecycle:lifecycle-runtime:2.7.0
83+
androidx.lifecycle:lifecycle-service:2.7.0
84+
androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0
85+
androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0
86+
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.7.0
87+
androidx.lifecycle:lifecycle-viewmodel:2.7.0
8788
androidx.loader:loader:1.0.0
8889
androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
8990
androidx.metrics:metrics-performance:1.0.0-alpha04
@@ -105,15 +106,15 @@ androidx.savedstate:savedstate:1.2.1
105106
androidx.sqlite:sqlite-framework:2.4.0
106107
androidx.sqlite:sqlite:2.4.0
107108
androidx.startup:startup-runtime:1.1.1
108-
androidx.tracing:tracing-ktx:1.1.0
109-
androidx.tracing:tracing:1.1.0
109+
androidx.tracing:tracing-ktx:1.3.0-alpha02
110+
androidx.tracing:tracing:1.3.0-alpha02
110111
androidx.vectordrawable:vectordrawable-animated:1.1.0
111112
androidx.vectordrawable:vectordrawable:1.1.0
112113
androidx.versionedparcelable:versionedparcelable:1.1.1
113114
androidx.viewpager:viewpager:1.0.0
114115
androidx.window:window:1.0.0
115-
androidx.work:work-runtime-ktx:2.9.0-rc01
116-
androidx.work:work-runtime:2.9.0-rc01
116+
androidx.work:work-runtime-ktx:2.9.0
117+
androidx.work:work-runtime:2.9.0
117118
com.caverock:androidsvg-aar:1.4
118119
com.google.accompanist:accompanist-drawablepainter:0.32.0
119120
com.google.accompanist:accompanist-permissions:0.32.0
@@ -168,8 +169,8 @@ com.google.guava:failureaccess:1.0.1
168169
com.google.guava:guava:31.1-android
169170
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
170171
com.google.j2objc:j2objc-annotations:1.3
171-
com.google.protobuf:protobuf-javalite:3.24.4
172-
com.google.protobuf:protobuf-kotlin-lite:3.24.4
172+
com.google.protobuf:protobuf-javalite:3.25.2
173+
com.google.protobuf:protobuf-kotlin-lite:3.25.2
173174
com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0
174175
com.squareup.okhttp3:logging-interceptor:4.12.0
175176
com.squareup.okhttp3:okhttp:4.12.0

app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class NavigationTest {
9090
lateinit var topicsRepository: TopicsRepository
9191

9292
private fun AndroidComposeTestRule<*, *>.stringResource(@StringRes resId: Int) =
93-
ReadOnlyProperty<Any?, String> { _, _ -> activity.getString(resId) }
93+
ReadOnlyProperty<Any, String> { _, _ -> activity.getString(resId) }
9494

9595
// The strings used for matching in these tests
9696
private val navigateUp by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_navigate_up)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
package com.google.samples.apps.nowinandroid.util
18+
19+
import android.util.Log
20+
import androidx.profileinstaller.ProfileVerifier
21+
import com.google.samples.apps.nowinandroid.core.network.di.ApplicationScope
22+
import kotlinx.coroutines.CoroutineScope
23+
import kotlinx.coroutines.guava.await
24+
import kotlinx.coroutines.launch
25+
import javax.inject.Inject
26+
27+
/**
28+
* Logs the app's Baseline Profile Compilation Status using [ProfileVerifier].
29+
*
30+
* When delivering through Google Play, the baseline profile is compiled during installation.
31+
* In this case you will see the correct state logged without any further action necessary.
32+
* To verify baseline profile installation locally, you need to manually trigger baseline
33+
* profile installation.
34+
*
35+
* For immediate compilation, call:
36+
* ```bash
37+
* adb shell cmd package compile -f -m speed-profile com.example.macrobenchmark.target
38+
* ```
39+
* You can also trigger background optimizations:
40+
* ```bash
41+
* adb shell pm bg-dexopt-job
42+
* ```
43+
* Both jobs run asynchronously and might take some time complete.
44+
*
45+
* To see quick turnaround of the ProfileVerifier, we recommend using `speed-profile`.
46+
* If you don't do either of these steps, you might only see the profile status reported as
47+
* "enqueued for compilation" when running the sample locally.
48+
*
49+
* @see androidx.profileinstaller.ProfileVerifier.CompilationStatus.ResultCode
50+
*/
51+
class ProfileVerifierLogger @Inject constructor(
52+
@ApplicationScope private val scope: CoroutineScope,
53+
) {
54+
companion object {
55+
private const val TAG = "ProfileInstaller"
56+
}
57+
58+
operator fun invoke() = scope.launch {
59+
val status = ProfileVerifier.getCompilationStatusAsync().await()
60+
Log.d(TAG, "Status code: ${status.profileInstallResultCode}")
61+
Log.d(
62+
TAG,
63+
when {
64+
status.isCompiledWithProfile -> "App compiled with profile"
65+
status.hasProfileEnqueuedForCompilation() -> "Profile enqueued for compilation"
66+
else -> "Profile not compiled nor enqueued"
67+
},
68+
)
69+
}
70+
}

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

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.samples.apps.nowinandroid
1818

1919
import android.os.Bundle
20-
import android.util.Log
2120
import androidx.activity.ComponentActivity
2221
import androidx.activity.SystemBarStyle
2322
import androidx.activity.compose.setContent
@@ -37,7 +36,6 @@ import androidx.lifecycle.Lifecycle
3736
import androidx.lifecycle.lifecycleScope
3837
import androidx.lifecycle.repeatOnLifecycle
3938
import androidx.metrics.performance.JankStats
40-
import androidx.profileinstaller.ProfileVerifier
4139
import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading
4240
import com.google.samples.apps.nowinandroid.MainActivityUiState.Success
4341
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
@@ -49,12 +47,9 @@ import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
4947
import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand
5048
import com.google.samples.apps.nowinandroid.ui.NiaApp
5149
import dagger.hilt.android.AndroidEntryPoint
52-
import kotlinx.coroutines.Dispatchers
5350
import kotlinx.coroutines.flow.collect
5451
import kotlinx.coroutines.flow.onEach
55-
import kotlinx.coroutines.guava.await
5652
import kotlinx.coroutines.launch
57-
import kotlinx.coroutines.withContext
5853
import javax.inject.Inject
5954

6055
private const val TAG = "MainActivity"
@@ -90,9 +85,7 @@ class MainActivity : ComponentActivity() {
9085
lifecycleScope.launch {
9186
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
9287
viewModel.uiState
93-
.onEach {
94-
uiState = it
95-
}
88+
.onEach { uiState = it }
9689
.collect()
9790
}
9891
}
@@ -152,48 +145,12 @@ class MainActivity : ComponentActivity() {
152145
override fun onResume() {
153146
super.onResume()
154147
lazyStats.get().isTrackingEnabled = true
155-
lifecycleScope.launch {
156-
logCompilationStatus()
157-
}
158148
}
159149

160150
override fun onPause() {
161151
super.onPause()
162152
lazyStats.get().isTrackingEnabled = false
163153
}
164-
165-
/**
166-
* Logs the app's Baseline Profile Compilation Status using [ProfileVerifier].
167-
*/
168-
private suspend fun logCompilationStatus() {
169-
/*
170-
When delivering through Google Play, the baseline profile is compiled during installation.
171-
In this case you will see the correct state logged without any further action necessary.
172-
To verify baseline profile installation locally, you need to manually trigger baseline
173-
profile installation.
174-
For immediate compilation, call:
175-
`adb shell cmd package compile -f -m speed-profile com.example.macrobenchmark.target`
176-
You can also trigger background optimizations:
177-
`adb shell pm bg-dexopt-job`
178-
Both jobs run asynchronously and might take some time complete.
179-
To see quick turnaround of the ProfileVerifier, we recommend using `speed-profile`.
180-
If you don't do either of these steps, you might only see the profile status reported as
181-
"enqueued for compilation" when running the sample locally.
182-
*/
183-
withContext(Dispatchers.IO) {
184-
val status = ProfileVerifier.getCompilationStatusAsync().await()
185-
Log.d(TAG, "ProfileInstaller status code: ${status.profileInstallResultCode}")
186-
Log.d(
187-
TAG,
188-
when {
189-
status.isCompiledWithProfile -> "ProfileInstaller: is compiled with profile"
190-
status.hasProfileEnqueuedForCompilation() ->
191-
"ProfileInstaller: Enqueued for compilation"
192-
else -> "Profile not compiled or enqueued"
193-
},
194-
)
195-
}
196-
}
197154
}
198155

199156
/**

app/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaApplication.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@ import android.app.Application
2020
import coil.ImageLoader
2121
import coil.ImageLoaderFactory
2222
import com.google.samples.apps.nowinandroid.sync.initializers.Sync
23+
import com.google.samples.apps.nowinandroid.util.ProfileVerifierLogger
2324
import dagger.hilt.android.HiltAndroidApp
2425
import javax.inject.Inject
25-
import javax.inject.Provider
2626

2727
/**
2828
* [Application] class for NiA
2929
*/
3030
@HiltAndroidApp
3131
class NiaApplication : Application(), ImageLoaderFactory {
3232
@Inject
33-
lateinit var imageLoader: Provider<ImageLoader>
33+
lateinit var imageLoader: dagger.Lazy<ImageLoader>
34+
35+
@Inject
36+
lateinit var profileVerifierLogger: ProfileVerifierLogger
3437

3538
override fun onCreate() {
3639
super.onCreate()
3740
// Initialize Sync; the system responsible for keeping data in the app up to date.
3841
Sync.initialize(context = this)
42+
profileVerifierLogger()
3943
}
4044

4145
override fun newImageLoader(): ImageLoader = imageLoader.get()

0 commit comments

Comments
 (0)