@RunWith(AndroidJUnit4::class)@LargeTestclassBaselineProfileGenerator{@get:Rulevalrule=BaselineProfileRule()@Testfungenerate(){rule.collect(packageName="com.example.app",includeInStartupProfile=true){// Launch directly into the NEWS_FEED.startActivityAndWait(Intent().apply{setPackage(packageName)setAction("com.example.app.NEWS_FEED")})}}}
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# Create Startup Profiles\n\nStartup Profiles are a subset of Baseline Profiles. Startup Profiles are used\nby the build system to further optimize the classes and methods they contain\nby improving the layout of code in your APK's DEX files. With Startup Profiles,\nyour app startup is usually between 15% and 30% faster than with Baseline\nProfiles alone.\n| **Note:** Startup Profiles impact your app's APK size, and the performance impact they provide might be large or small depending on how your app is structured. We recommend running an A/B test to assess the effect of Startup Profiles on your app.\n**Figure 1.** Code locality improvement from DEX layout optimization.\n\nRequirements\n------------\n\nWe recommend using Startup Profiles with the following tools:\n\n- Jetpack Macrobenchmark 1.2.0 or higher\n- Android Gradle Plugin 8.2 or higher\n- Android Studio Iguana or higher\n\nIn addition, you need the following settings in your app:\n\n- [R8](/build/shrink-code) enabled. For your release build, set `isMinifyEnabled = true`.\n- DEX layout optimizations enabled. In the `baselineProfile {}` block of the app module's build file, set `dexLayoutOptimization = true`.\n\nCreate a Startup Profile\n------------------------\n\n| **Note:** Unlike regular Baseline Profiles, Startup Profiles can't be contributed by libraries; Startup Profiles only include rules generated by the startup tests that you define, so make sure that you include all the main ways that users can enter your app.\n| **Note:** AGP 8.2 doesn't support distinct Startup Profiles per variant. If you're using AGP 8.2, use Baseline Profile Gradle plugin 1.2.3 or higher to automatically merge across variants. Upgrade to AGP 8.3 to use distinct Startup Profiles per variant.\n\nAndroid Studio creates a Startup Profile alongside a Baseline Profile when you\nuse the default Baseline Profile Generator template.\n\nThe general steps to create and generate a Startup Profile are the same as those\nto [create a Baseline Profile](/topic/performance/baselineprofiles/create-baselineprofile).\n\nThe default way to create a Startup Profile is by using the Baseline Profile\nGenerator module template from within Android Studio. This includes startup\ninteractions that form a basic Startup Profile. To augment this Startup Profile\nwith more Critical User Journeys (CUJs), add your app startup CUJs to a `rule`\nblock with `includeInStartupProfile` set to `true`. For simple apps, launching\nthe app's `MainActivity` might be sufficient. For more complex apps, consider\nadding the most common entry points into your app, such as starting the app from\nthe home screen or launching into a [deep link](/training/app-links/deep-linking).\n\nThe following code snippet shows a Baseline Profile generator (by default the\n`BaselineProfileGenerator.kt` file) that includes starting your app from the\nhome screen and launching into a deep link. The deep link goes directly to the\napp's news feed, not the app's home screen. \n\n @RunWith(AndroidJUnit4::class)\n @LargeTest\n class BaselineProfileGenerator {\n\n @get:Rule\n val rule = BaselineProfileRule()\n\n @Test\n fun generate() {\n rule.collect(\n packageName = \"com.example.app\",\n includeInStartupProfile = true\n ) {\n // Launch directly into the NEWS_FEED.\n startActivityAndWait(Intent().apply {\n setPackage(packageName)\n setAction(\"com.example.app.NEWS_FEED\")\n })\n }\n }\n }\n\nRun the [**Generate Baseline Profile for app** configuration](/topic/performance/baselineprofiles/create-baselineprofile#generate-profile) and find the\nStartup Profile rules at\n`src/\u003cvariant\u003e/generated/baselineProfiles/startup-prof.txt`.\n\nConsiderations to creating startup profiles\n-------------------------------------------\n\n| **Tip:** For the most performance improvement, try to limit the user journeys added to your startup profile so that you stay within one DEX file.\n| **Note:** To get the highest impact performance improvement from startup profile, the startup code should fit into the `classes.dex` file, which is the first DEX file. If that's not possible, the startup code will overflow into the next DEX files, which are then filled up with other classes and methods. See [Confirm Startup Profiles optimization](/topic/performance/baselineprofiles/confirm-startup-profiles) to find out if this happens, and what you can do to reduce your app's startup size to make it start faster.\n\nTo decide which user journeys to cover when creating a startup profile, consider\nwhere most users start the application. Usually that is from the launcher and\nafter they have been logged in. This is also the most basic baseline profile\njourney.\n\nAfter the first use case has been covered, follow the user funnel for app\nstartup. In many cases, app startup funnels follow this list:\n\n1. Main launcher activity\n2. Notifications that trigger app startup\n3. Optional launcher activities\n\nWork this list from the top and stop before classes.dex is full. To cover\nmore journeys afterwards, move code out of the startup path and add more\njourneys.\nTo move code out of the startup path, inspect Perfetto traces during app startup\nand look for long running operations. You can also use a [macrobenchmark](/topic/performance/benchmarking/macrobenchmark-overview)\nwith [method tracing enabled](/topic/performance/benchmarking/macrobenchmark-instrumentation-args#profiling-mode)\nfor an automatable and complete view of method calls during app startup.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Create Baseline Profiles {:#creating-profile-rules}](/topic/performance/baselineprofiles/create-baselineprofile)\n- [Baseline Profiles {:#baseline-profiles}](/topic/performance/baselineprofiles/overview)\n- [Writing a Microbenchmark](/topic/performance/benchmarking/microbenchmark-write)"]]