Skip to content

Commit d8bce64

Browse files
authored
Merge pull request #4 from android/adaptive-jetstream
Publishing AdaptiveJetStream
2 parents 1771a22 + b2069c4 commit d8bce64

File tree

215 files changed

+43553
-0
lines changed

Some content is hidden

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

215 files changed

+43553
-0
lines changed

AdaptiveJetStream/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
.DS_Store
4+
/build
5+
/captures
6+
.externalNativeBuild
7+
.cxx
8+
/.idea/
9+
local.properties
10+
.kotlin

AdaptiveJetStream/LICENSES.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Open source licenses and copyright notices
2+
3+
## [Coil](https://coil-kt.github.io/coil/#license)
4+
5+
Copyright 2022 Coil Contributors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
https://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
## [Big Buck Bunny Video](https://peach.blender.org/about/)
20+
21+
This work is licensed under
22+
a [Creative Commons Attribution 2.5](https://creativecommons.org/licenses/by/2.5/legalcode) license.
23+
24+
(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org

AdaptiveJetStream/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# **Adaptive Apps Samples: JetStream**
2+
3+
Jetstream is a sample media streaming application designed to adapt to various form factors using a single binary. It leverages Compose Material3 for cross-device compatibility, enabling [adaptive experiences](https://developer.android.com/adaptive-apps) across different form factors.
4+
5+
* Mobile device
6+
* Tablet
7+
* Foldable device
8+
* Chromebook
9+
* TV
10+
* Automotive
11+
* XR device
12+
13+
![Home screens on different form factors](Screenshots.png)
14+
15+
This directory contains a version of the JetStream TV sample app that utilizes [Compose Material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) components, with some exceptions like the [featured carousel](https://developer.android.com/design/ui/tv/guides/components/featured-carousel). It builds upon the original JetStream sample to offer experiences tailored to different device form factors. The original JetStream app for TV can be found at [https://github.com/android/tv-samples/](https://github.com/android/tv-samples/).
16+
17+
## Requirements
18+
19+
* You need Android Studio to try the sample app.
20+
* If you are trying JetStream on XR emulator, refer to [this document](https://developer.android.com/develop/xr/jetpack-xr-sdk/setup) for the details.
21+
* You can clone this repository and build the sample app in AdaptiveJetStream directory. Refer to [this document](https://developer.android.com/jetpack/compose/setup#sample) for the steps.
22+
23+
## Performance
24+
25+
The `benchmarks` module contains sample tests written using the [Macrobenchmark](https://developer.android.com/studio/profile/macrobenchmark) library. It also contains the test to generate the baseline profile for JetStream app.
26+
27+
### Baseline profiles
28+
29+
The baseline profile for this app is generated as `jetstream/src/release/generated/baselineProfiles/baseline-prof.txt`, which contains rules that enable AOT compilation of the critical user path taken during app launch. Refer to this [document](https://developer.android.com/studio/profile/baselineprofiles) to learn more about baseline profiles
30+
31+
## License
32+
33+
```
34+
Copyright 2025 Google LLC
35+
36+
Licensed under the Apache License, Version 2.0 (the "License");
37+
you may not use this file except in compliance with the License.
38+
You may obtain a copy of the License at
39+
40+
https://www.apache.org/licenses/LICENSE-2.0
41+
42+
Unless required by applicable law or agreed to in writing, software
43+
distributed under the License is distributed on an "AS IS" BASIS,
44+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45+
See the License for the specific language governing permissions and
46+
limitations under the License.
47+
```
48+

AdaptiveJetStream/Screenshots.png

1.69 MB
Loading
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Baseline Profiles
2+
3+
[Details on developer.android.com](https://developer.android.com/studio/profile/baselineprofiles)
4+
5+
6+
## Generating baseline profiles
7+
8+
To generate the baseline profile for Jetstream app, run "Generate Baseline Profile" from "**Run**".
9+
10+
> Note: The baseline profile needs to be re-generated for release builds that touch code which changes app startup.
11+
12+
To learn more on generating baseline profiles, follow this [Codelab](http://goo.gle/baseline-profiles).
13+
14+
15+
## Applying baseline profiles
16+
17+
Baseline profiles are automatically applied when an app is installed from the Play Store and also when running benchmark test cases.
18+
19+
20+
To apply the baseline profile when running the app from Android Studio, follow these steps:
21+
22+
23+
**Step-1**: Install and launch the app manually or follow this command:
24+
25+
```
26+
adb shell am start -n com.google.jetstream/com.google.jetstream.MainActivity
27+
```
28+
29+
> Note: When testing for performance, it is always best to install the release build of the app.
30+
31+
32+
**Step-2**: Compile the app with baseline profile using the following command:
33+
34+
```
35+
adb shell cmd package compile -f -m speed-profile com.google.jetstream
36+
```
37+
38+
39+
**Step-3**: Determine the status of profile by running the following:
40+
41+
```
42+
adb shell dumpsys package dexopt | grep -A 1 com.google.jetstream
43+
```
44+
45+
If the status is `status=speed-profile`, it means that baseline profile rules have been applied to optimize the app. Therefore, you can skip directly to **Step-5**.
46+
47+
If the status is different, follow the next step.
48+
49+
50+
**Step-4**: Execute the background optimizations by running the following command:
51+
52+
```
53+
adb shell cmd package bg-dexopt-job
54+
```
55+
56+
It executes a background task that typically takes about ~40 seconds to complete. Once complete, please follow **Step-3** again to verify the status.
57+
58+
59+
**Step-5**: Force close the app and launch it again manually or follow these commands:
60+
61+
```
62+
// Force close the app
63+
adb shell am force-stop com.google.jetstream
64+
65+
// Launch the app
66+
adb shell am start -n com.google.jetstream/com.google.jetstream.MainActivity
67+
```
68+
69+
Now, you can observe the improvement in the app's startup and overall performance as perceived by the end user.
70+
71+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import com.android.build.api.dsl.ManagedVirtualDevice
2+
3+
/*
4+
* Copyright 2023 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+
* https://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.test)
21+
alias(libs.plugins.kotlin.android)
22+
alias(libs.plugins.kotlin.serialization)
23+
alias(libs.plugins.compose.compiler)
24+
alias(libs.plugins.androidx.baselineprofile)
25+
}
26+
27+
kotlin {
28+
jvmToolchain(17)
29+
}
30+
31+
android {
32+
namespace = "com.google.jetstream.benchmark"
33+
compileSdk = 35
34+
35+
defaultConfig {
36+
minSdk = 28
37+
targetSdk = 35
38+
39+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
40+
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
41+
}
42+
43+
buildFeatures {
44+
compose = true
45+
buildConfig = true
46+
}
47+
48+
testOptions.managedDevices.devices {
49+
create<ManagedVirtualDevice>("tvApi34") {
50+
device = "Television (1080p)"
51+
apiLevel = 34
52+
systemImageSource = "aosp"
53+
}
54+
}
55+
56+
targetProjectPath = ":jetstream"
57+
}
58+
59+
baselineProfile {
60+
managedDevices += "tvApi34"
61+
useConnectedDevices = false
62+
}
63+
64+
65+
dependencies {
66+
implementation(libs.androidx.junit)
67+
implementation(libs.androidx.uiautomator)
68+
69+
// Support for TV activities with LEANBACK_LAUNCHER intent was added in 1.2.0-alpha03 release
70+
// Use 1.2.0-alpha03 or above versions for benchmarking TV apps
71+
implementation(libs.androidx.benchmark.macro.junit4)
72+
implementation(libs.androidx.rules)
73+
74+
implementation(platform(libs.androidx.compose.bom))
75+
implementation(libs.androidx.compose.runtime)
76+
}
77+
78+
androidComponents {
79+
beforeVariants(selector().withBuildType("benchmark").all()) {
80+
it.enable = true
81+
}
82+
}

0 commit comments

Comments
 (0)