0

I create such action before Android Studio bumblebee update and it was working fine.

fragment_button.setOnClickListener{
val action = FeedFragmentDirections.actionFeedFragmentToCountryFragment()
Navigation.findNavController(it).navigate(action)
}

But currently FragmentDirections are not accessible.I don't know where the problem comes from, I guess I can't manage to add navigation.

My build.gradle:

buildscript {
    dependencies {
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0")
    }
}
plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
    id 'com.google.gms.google-services' version '4.3.0' apply false

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My build.gradle App

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'kotlin-android-extensions'
}

android {
    dataBinding {
        enabled = true
}
dependencies {
    def navVersion = '2.4.0'

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation "androidx.navigation:navigation-fragment-ktx:$navVersion"
    implementation "androidx.navigation:navigation-ui-ktx:$navVersion"
}

4 Answers4

0

Have you tried cleaning and re-building your project?

This may be a similar case to: Safeargs library doesnt generate direction class

If not, given that you are having trouble accessing the FragmentDirections class, it may be due to the default addition of the non-transitive R class property in the Bumblebee update.

In the gradle.properties[app] file you will find:

# Enables namespacing of each library's R class so that its R class includes only the

# resources declared in the library itself and none from the library's dependencies,

# thereby reducing the size of the R class for that library

android.nonTransitiveRClass=true

A good summation of the change and solutions to migrating R classes can be found here:

https://blog.blundellapps.co.uk/speed-up-your-build-non-transitive-r-files/

Best of luck!

JHerscu
  • 68
  • 4
  • I tried the cases in the Safe Args library, but it didn't work for me as most of them were before the wasp update. I think I should add this to build.gradle but due to new update this is not added either. ``` "androidx.navigation.safeargs" ``` – Asım Odabaş Feb 06 '22 at 02:31
  • Ah! I can't believe I missed it before! Your app level Gradle file needs id 'androidx.navigation.safeargs.kotlin' – JHerscu Feb 06 '22 at 03:09
  • After opening a project with the same dependencies, I was able to get safe args to work and then break, by keeping and then commenting out that line respectively. – JHerscu Feb 06 '22 at 03:12
  • As I understand it, the problem is that the args gradle version is 2.4.0. I solved it by doing 2.3. When I wrote the 2.4.0 version, it was giving an error while adding safeargs to the build gradle file. – Asım Odabaş Feb 06 '22 at 04:06
0

I am retracting my previous answer!

After a bit of research, I realized the plugin block in your project-level build.gradle has the purpose of assigning dependencies that can be used by subprojects!

https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl

Instead of declaring:

plugins {
...
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
...                                                                     
}

You want to add id 'androidx.navigation.safeargs.kotlin' to the app-level plugins block so it can be used directly in your project.

JHerscu
  • 68
  • 4
0

I solved my problem by cleaning my project and rebuilding and adding.

Thank you very much for your support

Build.gradle

id ("androidx.navigation.safeargs") 

build


buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'

        def nav_version = "2.3.0"
        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
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'com.google.gms.google-services' version '4.3.0' apply false

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

0

okay so after bumblebee update gradle structure is changed.

but as mentioned above you can still add

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1")
    }
}

before the plugins{} in project level gradle.

but the better alternative is to just use

id 'androidx.navigation.safeargs.kotlin' version '2.4.1' apply false

in plugins{} at project level gradle

both of above will cover first step you still need to add

id 'androidx.navigation.safeargs.kotlin'

in plugins{} at app level gradle

**if you had already added these but now they are not resolving or cannot access fragment direction the reason might be because you have update you gradle to 7.1.0 and safe-args-plugin:2.4.0 is not compatible with that so make sure to use safe-args-plugin:2.4.1 or 2.5.0-alpha01 with gradle 7.1.0