Is it possible to view logging from Android Studio's preview renders?

Viewed 25

If I add logcat or system.out logs to compose view code, and then view the renders in Android Studio's preview... is it possible somewhere to view those logs?

It would be helpful when debugging views to be able to use the preview window, wondering if there is somewhere to see the logs of the code they run to generate these previews.

1 Answers

No, because that's not the purpose of the Compose preview. It is just a "preview", even in the interactive mode. It works by analysing data flow to and from variables in order to render the expected behaviour. If something cannot be properly defaulted/inferred, the preview pane displays an error, but that's different from log cat. That's logs specific to the Compose preview and are the only logs available to the feature. Fit example, if the viewModel is required to be passed as an argument, but due to initialisation/configuration problems, the object is not in a valid state, the preview may throw an error and not get rendered at all. Think of it as a prototype of the actual activity/Composable.

However,

I've observed anew feature that allows a preview to be deployed directly onto the device, in which case the logs might actually be generated and be viewable on the studio logcat. The button is just next to the interactive mode switch on the top right corner of the preview.

Related