SteveC
SteveC

Reputation: 1636

Jetpack Compose unable to view recomposition count

I'm working on an Android project that is using Jetpack Compose for the UI side, and it would be useful to be able to check the recomposition details in the Android Studio Layout Inspector, but the "Show Recomposition Counts" option doesn't appear if the app is running and selected. If the "Filter System-Defined" isn't set, it shows the system views, and checking that options shows the empty tree.

enter image description here

If one of the Compose Code-Labs apps is running, the option does appear, eg: enter image description here

So that proves the issue isn't an Emulator or an Android Studio version problem. I'm running Android Studio Electric Eel, 2022.1.1 Patch 1, and all apps are using the same emulator (API 33)

I've checked our project that shows the problem is using the same set of Compose libraries as the Code-Labs example does (which works), and in both instances I'm running a debug build.

Looking on StackOverflow I've seen mention of the issue elsewhere too, eg: Jetpack Compose: The layout inspector is not showing the menu for recomposition counts (but we're using the same Compose, Android Studio versions) so I'm running out of ideas. Any other suggestions for what might cause this?

Upvotes: 1

Views: 1734

Answers (2)

Ahmed Maad
Ahmed Maad

Reputation: 551

For me I chose a wrong view option. According to this issue tracker, there are two view options in the Layout Inspector. Make sure to choose the one besides the Component Tree.

Show Recomposition Counts

Upvotes: -1

SteveC
SteveC

Reputation: 1636

I've managed to track the issue down. For those that follow, I'd spotted the problem when the app was running, and looking on the "Run" tab to see the output when launching the LayoutInspector. By comparing the output when our app is running (which didn't work) with the Compose Code-Lab demo (which did work) that highlighted the log line:

ClassLoader.getResourceAsStream: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());

It turned out the cause was that our uses Shot for taking screenshots as part of the Compose tests, and we'd had a 'android:sharedUserId' property in the app manifest and the androidTest manifest. That doesn't appear to be needed any more, so I've removed that property from both manifests.

Following that change, the LayoutInspector can now see Jetpack Compose nodes, and from a quick test the latest Shot libraries can still take their screenshots in the Android Tests.

If you're getting the same ClassLoader error and the above fix isn't applicable to you, there was another article here about how to address the problem: Android: "Class loader may fail for processes that host multiple applications"

Upvotes: 0

Related Questions