google-developer-training / basic-android-kotlin-compose-training-mars-photos

Solution code for Android Basics in Kotlin course
https://developer.android.com/courses/android-basics-kotlin/course?gclid=CjwKCAjw4c-ZBhAEEiwAZ105RTyT-iaLHzrhMBUXdMhO230ZDwOwxxI2x4RgK8DwBxK8t1h0wmU_QxoCi4YQAvD_BwE
Apache License 2.0
72 stars 66 forks source link

Get Data from the Internet #145

Closed kollerma closed 5 months ago

kollerma commented 5 months ago

URL of codelab: https://developer.android.com/codelabs/basic-android-kotlin-compose-getting-data-internet

Specify the language of the codelab if it is not English: It's English.

In which task and step of the codelab can this issue be found? 8. Parse the JSON response with kotlinx.serialization

Describe the problem When following the instructions in the codelab, the app doesn't run. It terminates instantly with the following exception.

FATAL EXCEPTION: main
Process: com.example.marsphotos, PID: 18673
java.lang.IllegalArgumentException: Unable to create converter for java.util.List<com.example.marsphotos.model.MarsPhoto>
    for method MarsApiService.getPhotos
    at retrofit2.Utils.methodError(Utils.java:54)
    ...
Caused by: kotlinx.serialization.SerializationException: Serializer for class 'MarsPhoto' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
    at kotlinx.serialization.internal.PlatformKt.serializerNotRegistered(Platform.kt:31)
    ...

Comparing with the solution code, one can see that the instructions in the codelab use different versions for the serialization plugin and for the json serialization import.

The codelab has:

id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10"
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")

while the solution code has (in repo-starter):

id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")

Somehow, updating the versions fixes the problem.

Steps to reproduce

  1. Follow the codelab, use version 1.8.10 for the serialization plugin and 1.5.1 for the json serialization import
  2. Run the app
  3. See error in log cat
  4. Change plugin version to 1.9.10 for the serialization plugin and 1.6.0 for the json serialization import
  5. Run the app
  6. App works fine

Versions Android Studio version: Build #AI-241.14494.240.2411.11700778, built on April 11, 2024 API version of the emulator: 34

kollerma commented 5 months ago

Looks like this is a duplicate of https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/issues/134