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!

Popular Prag Prog topics Top

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
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
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
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
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
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
Or looking forward to? :nerd_face:
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New

Latest in PragProg

View all threads ❯