androidkotlinandroid-navigation

Class 'action' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections


I used version 2.4.0-alpha04 to conveniently use multi-backstack of navigation. (develop docs)

But I got the following error:

Class 'ActionDialogToWriteRoutine' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections

I first searched here to fix the error and found the question with the same error. (here)

I saw an answer in that link saying that the bug was fixed starting with v2.4.0-alpha02.

But I still get the same error.

So I'm posting the question again according to my situation.

What happened?

build.gradle[app]

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'

    // safe args
    id 'androidx.navigation.safeargs.kotlin'
}

dependencies {
    def lifecycle_version = "2.3.1"
    def nav_version = "2.4.0-alpha04"

    // AAC
    implementation("androidx.fragment:fragment-ktx:1.3.4")

    // Navigation Component
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

}

nav_graph.xml

<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/nav_graph"
    app:startDestination="@id/calendar">

    <include app:graph="@navigation/calendar"/>
    <include app:graph="@navigation/list"/>
    <include app:graph="@navigation/write_home"/>
</navigation>

write_home.xml

<?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/write"
    app:startDestination="@id/home">

    <fragment
        android:id="@+id/home"
        android:name="com.example.writeweight.fragment.WriteRoutineHomeFragment"
        android:label="fragment_write_routine_home"
        tools:layout="@layout/fragment_write_routine_home" >
        <action
            android:id="@+id/action_home_to_dialog"
            app:destination="@id/dialog" />
    </fragment>
    <fragment
        android:id="@+id/dialog"
        android:name="com.example.writeweight.fragment.BodyPartDialogFragment"
        android:label="BodyPartDialogFragment"
        tools:layout="@layout/fragment_body_part_dialog">
        <action
            android:id="@+id/action_dialog_to_write_routine"
            app:destination="@id/write_routine" />
    </fragment>
    <fragment
        android:id="@+id/write_routine"
        android:name="com.example.writeweight.fragment.WriteRoutineFragment"
        android:label="WriteRoutineFragment"
        tools:layout="@layout/fragment_writing_routine">
        <argument
            android:name="title"
            app:argType="string"
            app:nullable="true"
            android:defaultValue="@null"/>
        <argument
            android:name="workout"
            app:argType="string"
            app:nullable="true"
            android:defaultValue="@null"/>
        <action
            android:id="@+id/action_write_routine_to_workout_tab"
            app:destination="@id/workout_tab" />
    </fragment>
    <fragment
        android:id="@+id/workout_tab"
        android:name="com.example.writeweight.fragment.WorkoutListTabFragment"
        android:label="WorkoutListTabFragment"
        tools:layout="@layout/fragment_workout_list_tab">
        <action
            android:id="@+id/action_workout_tab_to_write_routine"
            app:destination="@id/write_routine" />
    </fragment>
</navigation>

Solution

  • in your app level build.gradle file replace

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

    with

    plugins {
        id 'androidx.navigation.safeargs'
    }
    

    as James Bond mentions
    Don't forget to update versions of the navigation libraries that are in the top level gradle file and module's gradle file to the same value! stackoverflow.com/a/68331336