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

8

57

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"
Gillespie answered 19/5, 2021 at 19:46 Comment(5)
did u try invalidating cache and restart?Misread
Yes, for sure, I tried another android Studio version xDGillespie
That sounds like this issue, but that issue only affects Navigation 2.4.0-alpha01. Are you sure you aren't using Navigation 2.4.0-alpha01?Nerissanerita
yes I am using navigation androidx.navigation:navigation-compose:2.4.0-alpha01 for compose since part of the project is written in android composeGillespie
even after downgrading the dependency mentioned in my previous comment to androidx.navigation:navigation-compose:1.0.0-alpha10, I am still facing the same issueGillespie
F
79

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")
}
Finisterre answered 25/5, 2021 at 4:14 Comment(5)
This was a quick way of working around the same issue for me, thanks. Are there any drawbacks of using the non-Kotlin version?Incomprehensive
You can't use named arguments for example.Publisher
What is the cause of this problem?... What is the difference between these two pluginsCrapshooter
@Venkataramanan, to generate Java language code suitable for Java or mixed Java and Kotlin modules use androidx.navigation.safeargs, to generate Kotlin code suitable for Kotlin-only modules use androidx.navigation.safeargs.kotlin, from hereEpigeal
Three years later still valid.Tamarau
C
42

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'
}
Curr answered 10/7, 2021 at 20:34 Comment(2)
This solution works for me. Changing from "2.3.5" to "2.4.0-alpha04" fix my error. Got some warnings ⚠ when building, but works. ThanksGlycogen
Thanks, I just forgot to update the nav_version of androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version in the top-level gradle file to the same nave_version which is in the module's gradle file.Ultramundane
A
13

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

Australopithecus answered 19/10, 2021 at 22:32 Comment(0)
H
11

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)
Hued answered 3/6, 2021 at 11:49 Comment(4)
Still have this bug, any fix?Clomb
The bug should be fixed by that release. If the problem still persist for you, place your comment on the tracker or create a new issue.Hued
Got same bug on '2.4.0-alpha06' so it is not fully fixed or some regression happendMeanwhile
Sounds like a regression bug then @MichałTajchert, in such case I’d bet there’s an existing issue on the tracker.Hued
B
2

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"
Bennet answered 29/1, 2022 at 12:43 Comment(0)
E
1

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'
Entebbe answered 13/4, 2022 at 6:17 Comment(0)
I
1

Please change your build.gradle(:app) file

from

apply plugin: "androidx.navigation.safeargs.kotlin"

to

apply plugin: "androidx.navigation.safeargs" 
Idocrase answered 28/10, 2023 at 7:25 Comment(0)
S
0

2.4.0-beta02 at this moment available

Stutter answered 28/11, 2021 at 14:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.