Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To activate metrics for composing in an android application, follow these steps:

  1. Add the dependency for the Compose UI toolkit to your project build.gradle file:
dependencies {
    implementation "androidx.compose.ui:ui:${compose_version}"
    // other Compose dependencies as needed
}
  1. Enable Metrics in your application's MainActivity class by adding the following code to the onCreate() method:
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Enable Metrics
        val compositionMetrics = androidx.compose.ui.tooling.ComposePerformanceMetrics()
        setContent {
            // your Composable content
        }
    }
}
  1. Run your application on an emulator or physical device. Metrics for composing will be collected and displayed in the Logcat console. You can filter the logs by tag ComposeBenchmark.

Note: Metrics for composing are primarily intended for use in development and debugging, and should not be enabled in production builds.