dachristenson

dachristenson

Kotlin and Android Development featuring Jetpack: No activity_main.xml anymore

I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity_main.xml”. Following the instructions, I was able to build and run the project until this point on my Samsung tablet and in the emulator. However, this paragraph starts out mentioning activity_main.xml and also layout_main.xml, neither of which were created by Android Studio when creating the project.

I did some googling and found that, apparently, as of Android Studio 2022.2 Flamingo released in April 2023, Google changed from using XML to define the layout to using Kotlin only with “Jetpack Compose”. However, I found suggestions from other users that all they needed to do to use the old way was to add activity_main.xml to …/res/layout. After that, they claimed that it worked as before.

So, I tried this, creating …/res/layout/activity_main.xml exactly as described on p. 24 and re-writing MainActivity.kt exactly as described on p. 26. The project builds and loads “successfully” (per Android Studio’s messages) on my Samsung tablet, but all it does is show a white screen for a fraction of a second before crashing. I tried with the emulator, and it did the exact same thing! Unable to find where I went wrong, I re-created the entire project under a different name and followed the book exactly, hoping to fix whatever error I couldn’t see. However, the new project behaves exactly as before. On both real tablet and emulator, trying to launch the app two or three times brings up a message about how Penny Drop (or other name) keeps crashing and asking me if I want to force close it.

I then downloaded the provided project code from the book’s website and tried that, but it won’t even build! Android Studio gives me several errors when I try to do so. The fact that Google apparently so radically changed Android (or at least Android Studio) in the rather short time since this book was printed – and didn’t even provide tools to recognize that it was an “old” project and update it to run – is quite frustrating.

Could you offer any suggestions on how to get past these issues and enjoy (and learn from) the rest of this book, please? Thanks in advance!

First Post!

mfazio23

mfazio23

Author of Kotlin and Android Development featuring Jetpack

Hey Derek!
Thanks so much for the heads up and overview of your troubles! The reality of the situation is that Android Studio has changed quite a bit from when the book was written, so there are extra concerns with trying to get up and running.

We’ve dealt with a few of those issues in other threads on this forum, which could help. Also, I’m going to put together an FAQ post about trying to get up and running with newer versions of Android Studio.

As far as Compose, that was barely in Alpha when the book was released which is why I went with classic XML views for the whole thing. I happen to love Compose, but most places are still partially or fully XML for UI.

I definitely understand the frustration - just after the book came out Google made a change to AS that removed a variable I assumed was there, breaking things on page 7.

I’ll reply here once I get that FAQ together and then you can see if it helps. Otherwise, feel free to post again with specific issues and I can help from there.

Where Next?

Popular Pragmatic Bookshelf topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
jgchristopher
“The ProductLive.Index template calls a helper function, live_component/3, that in turn calls on the modal component. ” Excerpt From: Br...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New

Sub Categories:

OSZAR »