'Android Studio Bumblebee Navigation can't access FragmentDirections for action
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"
}
Solution 1:[1]
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.
Solution 2:[2]
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!
Solution 3:[3]
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
}
Solution 4:[4]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Justin Herscu |
| Solution 2 | Justin Herscu |
| Solution 3 | As?m Odaba? |
| Solution 4 |
