DEV Community

Swathi Vennela
Swathi Vennela

Posted on

Safeargs plugin not generating direction classes

I'm trying to use safeargs plugin (for the first time) to pass data and navigate from one fragment to another. After adding the arguments in the destination fragment in the navigation graph, and choosing rebuild, I'm not getting the autogenerated directions class and Args class.
I followed the official docs and added the necessary dependecies for safeargs. I did set android.useAndroidX to true in the gradle.properties as well.

My app level build.gradle file:

plugins {
    id 'com.android.application'
    id 'androidx.navigation.safeargs'
}
android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.fragnavpractise"
        minSdk 23
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    def nav_version = "2.4.1"
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    // Java language implementation
    implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"
    // Kotlin
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    // Feature module Support
    implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
    // Testing Navigation
    androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
    // Jetpack Compose Integration
    implementation "androidx.navigation:navigation-compose:$nav_version"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Enter fullscreen mode Exit fullscreen mode

My Project level build.gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
    }
    dependencies {
        def nav_version = "2.4.1"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
    }
}
plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false

}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Enter fullscreen mode Exit fullscreen mode

My 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/payment_navigation_graph"
    app:startDestination="@id/launchFragment">

    <fragment
        android:id="@+id/launchFragment"
        android:name="com.example.fragnavpractise.LaunchFragment"
        android:label="fragment_launch"
        tools:layout="@layout/fragment_launch" >
        <action
            android:id="@+id/action_launchFragment_to_payFragment"
            app:destination="@id/payFragment" />
    </fragment>
    <fragment
        android:id="@+id/payFragment"
        android:name="com.example.fragnavpractise.PayFragment"
        android:label="fragment_pay"
        tools:layout="@layout/fragment_pay" >
        <action
            android:id="@+id/action_payFragment_to_finishFragment"
            app:destination="@id/finishFragment" />
    </fragment>
    <fragment
        android:id="@+id/finishFragment"
        android:name="com.example.fragnavpractise.FinishFragment"
        android:label="fragment_finish"
        tools:layout="@layout/fragment_finish" >
        <action
            android:id="@+id/action_finishFragment_to_launchFragment"
            app:destination="@id/launchFragment" />
        <argument
            android:name="payee_name"
            app:argType="string"
            app:nullable="true" />
    </fragment>
</navigation>
Enter fullscreen mode Exit fullscreen mode

Please help me resolve this.

Top comments (0)