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!