简体   繁体   中英

Android SafeArgs Navigation Unreslved Reference camelcase kotlin vs underscore xml

I have a fragment that uses:

 val action = LoginFragmentDirections.actionLoginToHome()
        findNavController().safeNavigate(action)

and the Navigation graph XML is declared as:

<fragment
        android:id="@+id/loginFragment"
        android:name="com.myapp.LoginFragment"
        android:label="login_fragment"
        tools:layout="@layout/login_fragment">

        <action
            android:id="@+id/action_login_to_home"
            app:destination="@+id/homeFragment"
            app:launchSingleTop="true"
            app:popUpTo="@navigation/nav_graph_main"
            app:popUpToInclusive="false" />

    </fragment>

The Android studio compiler doesn't throw any errors and I can even navigate from the actionLoginToHome() function to the XML file by using cmd click. However, when building the app the gradle compilation throws the error:

**Unresolved reference: actionLoginToHome** 

Root Gradle:

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.2"

Module Gradle:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'androidx.navigation.safeargs.kotlin'
}

... dependencies..

implementation "androidx.navigation:navigation-fragment-ktx:2.5.2"
implementation "androidx.navigation:navigation-ui-ktx:2.5.2"

Ok Solved,

The graph was a nested XML of several navigations, one of the navigation fragments in the nested files had the same ID and action than the one with the problem, probably due to a wrongful copy paste.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM