The live literals feature and @Preview annotation ...
# compose
c
The live literals feature and @Preview annotation shown at AndroidDevSummit gets me excited to use that stuff, but I basically only use composable in a separate library. Was there an issuetracker for supporting @Preview in library modules that we could star? (I tried a quick search and no luck)
a
Are you talking about the preview in the IDE or the "deploy to device" feature? Preview should work out of the box in library modules and "deploy to device" works if you manually add a run configuration.
n
yeah actually it’s was in AS since the begin of the compose release, wasn’t it ?
I did observe live change in emulator and it’s always nice to see, but you have to change an existing value (dp, string), adding or removing any line of code will break it until next deploy
c
Really? Let me try again. I swear it didn't work a few months ago.
I must be doing something wrong...
I'm on latest compose, latest everything really. lol
Here is the dep I added
Copy code
implementation("androidx.compose.ui:ui-tooling-preview:1.1.0-beta01")
a
When you see this you should click the red circle in the top right and see what the error is. Also note that you need the latest versions of
androidx.savedstate:savedstate
and
androidx.lifecycle:lifecycle-viewmodel
as dependencies. These are already transitive dependencies of
androidx.activity:activity
but if you module doesn't depend on androidx.activity you may need to declare these manually (
debugImplementation
should be enough).
c
Hm. Let me give it a whirl now.
Alright. I started fresh again. I have this
Alt enter gives me this
I select ui tooling prev
It added this
Red
@Preview
went away
Sync and rebuild
Added implementation("androidx.activityactivity1.4.0"), rebuilt, same issue
c
I do have ui tooling?
oh snap. ui-tooling and ui-tooling preview are different. shit.
That was it. It works. Albert to the rescue... again. Cheers
👍 1
I suppose both could just be debugImplementation right?
Copy code
debugImplementation("androidx.compose.ui:ui-tooling-preview:1.1.0-beta01")
debugImplementation("androidx.compose.ui:ui-tooling:1.1.0-beta01")
Hopefully they can improve the experience. Thanks again albert
a
As the message I posted above said
androidx.compose.ui:ui-tooling-preview
must be
implementation
or the compilation of release build won’t succeed.
👍 1
c
If anyone stumbles upon this thread. I had to add
Copy code
implementation("androidx.activity:activity:1.4.0")
too. If I remove it, it stops working.
a
You can make it a
debugImplementation
. Or alternatively:
Copy code
debugImplementation("androidx.savedstate:savedstate:1.1.0")
debugImplementation("androidx.lifecycle:lifecycle-viewmodel:2.4.0")
c
AH okay. I guess I misunderstood. So I can have debug of activity, but ui-tooling and preview need to be implementation? Do I have it right now?
a
users now have the option to add ui-tooling-preview as
an implementation API and ui-tooling as debugImplementation
ui-tooling
depends on
ui-tooling-preview
so if you add
ui-tooling
as
implementation
you don’t need to explicitly declare
ui-tooling-preview
. However
ui-tooling-preview
is needed for compilation so if
ui-tooling
is
debugImplementation
you need to add
ui-tooling-preview
as
implementation
.
❤️ 1