I wanted to convert the XML code to Jetpack Compose code using the Recompose plugin (https://github.com/pocmo/recompose).
The following error occurs when trying to install a plug-in: Error
My version of Android Studio: About Android Studio
Please help.
It looks like recompose has not been updated to run as a plugin in the later Android Studio versions. You can still run recompose from the command line. My experience was that it was limited and could not handle a large amount of my layout XML, as I have a good bit of logic around animations, layer-lists, themed vector assets, dynamically updated texts and drawables, and conditional visibility.
To try with the command line, you can use something like this
./gradlew recompose-cli:run --args="C:\Users\Admin\AndroidStudioProjects\SmarterGarage\sglibrary\src\main\res\layout\activity_main.xml"
Related
I've an application that uses Fragmnent Views with XML resources and I want to migrate it to Compose. Being the app quite big, I decided to temporarily have a mixed environment with Compose working together with the old XML resources, so I created a new Compose fragment and I succeeded to add the standard navigation action to navigate to it. The code builds successfully, but when I try to run the app I get the error of the picture below. It is particularly wierd because this error appears immediately, and not in the build panel, but in a popup dialog. Any hint ?
Ok, the documentation is not very clear, but in the end I found this:
"You can also include a ComposeView directly in a fragment if your full screen is built with Compose, which lets you avoid using an XML layout file entirely."
Being my app a hybrid one with XML navigation graphs, it looks like I need to define an XML resource anyway.
I hoped I cound avoid defining an XML layout, but it seems I need one for a fragment that has an old fashioned Activity as parent.
I'll post an update as soon as I discover something new
UPDATE
Adding an XML layout didn't fix the problem.
In fact the XML layout is not necessary. I don't really understand the cause of that error, but after cleaning a couple of times the project and clearing A.S. cache it disappeared. I succeeded to add a Compose Fragment to an old XML resources style app. The old navigation works without problems. Hope this post will help someone else save the time I have wasted...
any idea to make android studio Jetpack compose auto refresh like Hot reload in Flutter it's annoying! Is there Auto-refresh in Jetpack Compose viewer?
Right now, compose does not support Hot reloads.
But Literals values can be updated directly.
Some supported types.
Int
String
Color
Dp
Boolean
You can view constant literals that trigger real-time updates without the compilation step by enabling these highlighted values.
Reference
When Android Studio Electric Eel becomes stable, Live Edit is enabled by default that acts as Hot Reload. Right now its still on preview.
I use Compose with AS Arctic Fox v2020.3.1. When I update the code, the preview does not render in real-time. AS show the message "The preview is out of date" and I must click "Build & Refresh". I'd like it to render UI in real-time, similar to XML Design.
How do it?
Thanks in advance.
AFAIK you can't. You're able to edit string values and certain others, such as padding dp's but when adding or removing elements, you have to rebuild to view the updated layout.
I am using Android Studio 3.3.2. I didn't find the NumberPicker in the palette which was in Expert tab on older versions of Android Studio. What to do?Screenshot of my palette are given below:
Just type in <NumberPicker in the XML File and Studio will suggest the NumberPicker.
From there on you can adjust it also in the Design View.
I added a button and then had everything between the opening angular brace and forward slash deleted, then i simply typed NumberPicker (yes it was suggested) and vola! It appeared.
I'm new to developing with Android, and the biggest new thing is the way the UI is rendered (relative to other views instead of absolute locations and sizes). As a result, I've been experimenting a lot with layouts, and find myself changing 1 view or even just 1 property of a view, then having to recompile and launch it back into the emulator to see the result. Is there a tool that quickly (or at least quicker) shows what a UI looks like give a layout xml file?
You can look at http://www.droiddraw.org/ but it is not perfect.
You can use Eclipse with Android Development Tools, when opening a layout file you get a preview of what looks like. Besides, ADT provides some nice features for developing and debugging in the Android platform.
When you're in the XML view, simply click the "Layout" tab on the bottom, and you'll be taken to a visual representation of your layout:
Like so:
There are some limitations for sure (e.g. text shadowing, for one, will not be depicted in this view), but it's a good way to get a general idea of how your layout is working.
Versions 2.x and higher of Android Studio render the XML in real-time in the Preview pane of the IDE and it even juxtaposes the XML and outline views side by side.