google-developer-training / first-android-app

Repository for Build Your First Android App codelabs (Java and Kotlin)
7 stars 6 forks source link

Enable SafeArgs instructions are badly out of date #175

Open grahammitchell opened 2 years ago

grahammitchell commented 2 years ago

I'm using AndroidStudio Bumblebee:

Android Studio Bumblebee | 2021.1.1 Build #AI-211.7628.21.2111.8092744, built on January 18, 2022 Runtime version: 11.0.11+0-b60-7590822 amd64

Under 9. Task: Implement the second fragment, "Step 5: Enable SafeArgs" is so out of date I'm struggling to get the dependency added.

First, it says "Find the dependencies section In the buildscript section" but the top-level .gradle file was not generated with a buildscript section at all.

Eventually, I ended up with something like the following added to the top of this file:

buildscript {
    repositories {
        google()
    }
    dependencies {
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0")
    }
}

Then in the module-level build.gradle, I added the following to the plugins section:

plugins {
   ...
    id 'androidx.navigation.safeargs.kotlin'
}

This sort-of works, in the sense that it no longer gives me an error about being unable to load the safe-args-plugin classpath. However, I still can't do the Gradle project sync -- it fails with the following ominous error:

Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.

This is an unexpected error. Please file a bug containing the idea.log file.

I know this message isn't intended for the authors of this tutorial, but I've included it anyway in the unlikely event that it's helpful.

idea.log

Nickrader commented 2 years ago

https://developer.android.com/codelabs/build-your-first-android-app-kotlin?index=..%2F..%2Findex#8 Step 5: Enable SafeArgs

Tutorial gives def nav_version = "2.3.0-alpha02" ?Should be? def nav_version = "2.5.0-alpha01" now? Idk, I don't have a codebase to compare this to but snippets from other users and my newly acquired limited knowledge of java ;) If I put 2.3.x or 2.4.x for nav-version I get error, but 2.5.0-alpha01 working for me.

It works if I do that, but I tried the 'troubleshooting' and that is also a bit outdated, (https://developer.android.com/guide/navigation/navigation-pass-data#Safe-args), giving 2.4.0 Luckily for my purposes of continuing the tutorial, using latest maven repo helped. The random_button lives! https://mvnrepository.com/artifact/androidx.navigation/navigation-safe-args-gradle-plugin/2.5.0-alpha01

Edit: I seem to have switched back and forth between https://developer.android.com/codelabs/build-your-first-android-app and https://developer.android.com/codelabs/build-your-first-android-app-kotlin

Also had to use plugins { id("androidx.navigation.safeargs") } not plugins { id("androidx.navigation.safeargs.kotlin") } for gradle to sync.