A fully functional Android app built entirely with Kotlin and Jetpack Compose
Adds ProfileViewer to log the app's Baseline Profile Compilation Status
Murat Yener7b5c0f2be887
diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.ktindex 79d556f73..6fc795d8c 100644--- a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt+++ b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt@@ -17,6 +17,7 @@package com.google.samples.apps.nowinandroidimport android.os.Bundle+import android.util.Logimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.viewModels@@ -35,6 +36,7 @@ import androidx.lifecycle.Lifecycleimport androidx.lifecycle.lifecycleScopeimport androidx.lifecycle.repeatOnLifecycleimport androidx.metrics.performance.JankStats+import androidx.profileinstaller.ProfileVerifierimport com.google.accompanist.systemuicontroller.rememberSystemUiControllerimport com.google.samples.apps.nowinandroid.MainActivityUiState.Loadingimport com.google.samples.apps.nowinandroid.MainActivityUiState.Success@@ -47,11 +49,15 @@ import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfigimport com.google.samples.apps.nowinandroid.core.model.data.ThemeBrandimport com.google.samples.apps.nowinandroid.ui.NiaAppimport dagger.hilt.android.AndroidEntryPoint+import kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.flow.collectimport kotlinx.coroutines.flow.onEachimport kotlinx.coroutines.launch+import kotlinx.coroutines.withContextimport javax.inject.Inject+private const val TAG = "MainActivity"+@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)@AndroidEntryPointclass MainActivity : ComponentActivity() {@@ -133,12 +139,48 @@ class MainActivity : ComponentActivity() {override fun onResume() {super.onResume()lazyStats.get().isTrackingEnabled = true+ lifecycleScope.launch {+ logCompilationStatus()+ }}override fun onPause() {super.onPause()lazyStats.get().isTrackingEnabled = false}++ /**+ * Logs the app's Baseline Profile Compilation Status using [ProfileVerifier].+ */+ private suspend fun logCompilationStatus() {+ /*+ When delivering through Google Play, the baseline profile is compiled during installation.+ In this case you will see the correct state logged without any further action necessary.+ To verify baseline profile installation locally, you need to manually trigger baseline+ profile installation.+ For immediate compilation, call:+ `adb shell cmd package compile -f -m speed-profile com.example.macrobenchmark.target`+ You can also trigger background optimizations:+ `adb shell pm bg-dexopt-job`+ Both jobs run asynchronously and might take some time complete.+ To see quick turnaround of the ProfileVerifier, we recommend using `speed-profile`.+ If you don't do either of these steps, you might only see the profile status reported as+ "enqueued for compilation" when running the sample locally.+ */+ withContext(Dispatchers.IO) {+ val status = ProfileVerifier.getCompilationStatusAsync().get()+ Log.d(TAG, "ProfileInstaller status code: ${status.profileInstallResultCode}")+ Log.d(+ TAG,+ when {+ status.isCompiledWithProfile -> "ProfileInstaller: is compiled with profile"+ status.hasProfileEnqueuedForCompilation() ->+ "ProfileInstaller: Enqueued for compilation"+ else -> "Profile not compiled or enqueued"+ }+ )+ }+ }}/**diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex b0046ff66..d3262ab9c 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -18,7 +18,7 @@ androidxLifecycle = "2.6.0-alpha05"androidxMacroBenchmark = "1.2.0-alpha16"androidxMetrics = "1.0.0-alpha03"androidxNavigation = "2.5.3"-androidxProfileinstaller = "1.2.1"+androidxProfileinstaller = "1.3.1"androidxStartup = "1.1.1"androidxTestCore = "1.5.0"androidxTestExt = "1.1.4"