Android studio build error in navigation component, action is not abstract and does not implement abstract member actionID

Viewed 12573

Out of nowhere, the build is crashing with a strange error related to the navigation component even though it used to work before, the error is in the generated class, in my case NativeLanguageSelectionFragmentDirections

Here is the error

e: C:\Users\David\StudioProjects\android\app\build\generated\source\navigation-args\debug\com\linguistic\linguistic\framework\presentation\loginscreens\ui\main\NativeLanguageSelectionFragmentDirections.kt: (10, 16): Class 'GoToSelectLearningLangAction' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections
e: C:\Users\David\StudioProjects\android\app\build\generated\source\navigation-args\debug\com\linguistic\linguistic\framework\presentation\loginscreens\ui\main\NativeLanguageSelectionFragmentDirections.kt: (13, 12): 'getActionId' overrides nothing
e: C:\Users\David\StudioProjects\android\app\build\generated\source\navigation-args\debug\com\linguistic\linguistic\framework\presentation\loginscreens\ui\main\NativeLanguageSelectionFragmentDirections.kt: (15, 12): 'getArguments' overrides nothing

And here is the code of the navigation graph

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/first_login_graph.xml"
    app:startDestination="@id/nativeLanguageSelectionFragment">

    <fragment
        android:id="@+id/nativeLanguageSelectionFragment"
        android:name="com.linguistic.linguistic.framework.presentation.loginscreens.ui.main.NativeLanguageSelectionFragment"
        android:label="NativeLanguageSelectionFragment"
        tools:layout="@layout/language_selection_fragment">
        <action
            android:id="@+id/goToSelectLearningLangAction"
            app:destination="@id/learningLanguageSelectionFragment"
            app:enterAnim="@anim/slide_in_right"
            app:exitAnim="@anim/slide_out_left"
            app:popEnterAnim="@anim/slide_in_left"
            app:popExitAnim="@anim/slide_out_right"
            app:popUpTo="@id/nativeLanguageSelectionFragment"
            app:popUpToInclusive="true" />
    </fragment>
    <fragment
        android:id="@+id/learningLanguageSelectionFragment"
        android:name="com.linguistic.linguistic.framework.presentation.loginscreens.ui.main.LearningLanguageSelectionFragment"
        android:label="LearningLanguageSelectionFragment"
        tools:layout="@layout/language_selection_fragment">
        <argument
            android:name="nativeLanguageID"
            app:argType="string"
            app:nullable="true" />
        <action
            android:id="@+id/action_learningLanguageSelectionFragment_to_welcomeFragment"
            app:destination="@id/welcomeFragment"
            app:enterAnim="@anim/slide_in_right"
            app:exitAnim="@anim/slide_out_left"
            app:popEnterAnim="@anim/slide_in_left"
            app:popExitAnim="@anim/slide_out_right"
            app:popUpTo="@id/learningLanguageSelectionFragment"
            app:popUpToInclusive="true" />
    </fragment>
    <fragment
        android:id="@+id/welcomeFragment"
        android:name="com.linguistic.linguistic.framework.presentation.loginscreens.ui.main.WelcomeFragment"
        android:label="fragment_welcome"
        tools:layout="@layout/fragment_welcome" />
</navigation>

I am using

 "androidx.navigation:navigation-fragment-ktx:2.3.5"
 "androidx.navigation:navigation-ui-ktx:2.3.5"
7 Answers

I had this problem too. Until they release the fix. Please try this:

plugins {
  id("androidx.navigation.safeargs")
}

instead of

plugins {
  id("androidx.navigation.safeargs.kotlin")
}

As for my case, I had to update Safe Arg plugin as well to get rid of the error message.

[build.gradle]
buildscript {
    ...
    dependencies {
        ...
        classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha04'
}

[app/build.gradle]
dependencies {
    ...
    implementation 'androidx.fragment:fragment-ktx:1.4.0-alpha04'
    api 'androidx.navigation:navigation-fragment-ktx:2.4.0-alpha04'
    api 'androidx.navigation:navigation-ui-ktx:2.4.0-alpha04'
}

Since the version v2.4.0-alpha02 was released, this known bug is no longer present.

Bug Fixes

  • Safe Args no longer crashes when attempting to generate direction properties in Kotlin. (Id2416, b/188564435)

All of these dependencies

androidx.navigation:navigation-fragment-ktx
androidx.navigation:navigation-ui-ktx
androidx.navigation:navigation-safe-args-gradle-plugin

need to be using the same version - ex: at the time of writing this it's 2.4.0-alpha10

just update the safe-args dependency to the latest version(>=2.4.0-rc01) too!:

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-rc01"

in my case, I get this error for my new module. I added the safe-args classPath in build.gradle (project)

KOTLIN-DSL:

    "classpath"(group = "androidx.navigation",name = "navigation-safe-args-gradle-plugin", version = "2.4.1")

without the plunging in my module build.gradle. so I added this on top of build.gradle:

id("androidx.navigation.safeargs.kotlin")

GROOVY:

classpath  "navigation-safe-args-gradle-plugin : 2.4.1"

and:

id 'androidx.navigation.safeargs.kotlin'

2.4.0-beta02 at this moment available

Related