I'm migrating several apps to use the Navigation Component, and I ran into a problem - the Directions/Args classes generated by the android-safe-args-gradle-plugin
are not being recognized in Android Studio.
Code demonstrating this problem is located at github.com/wooldridgetm/android-navigation.git, but crux of the matter is, in the code below, HomeFragmentDirections isn't recognized. This is taken from the class HomeFragment
, lines 76 - 82.
val b2 = view.findViewById<Button>(R.id.navigate_action_button)
b2.setOnClickListener {
// PROBLEM: HomeFragmentDirections isn't recognized.
val action = HomeFragmentDirections.nextAction()
// PROBLEM: results in Unresolved reference: flowStepNumber
// action.flowStepNumber = 1
findNavController().navigate(action)
}
I know what the documentation says & I know that class HomeFragmentDirections
is being generated by the plugin & is located at app/build/generated/source/navigation-args/debug/code/example/android/codelabs/navigation, but it is not recognized by AS.
I also know that this did work pre-v2 of the plugin...but it's not working now & I can't even get a simple example to behave as expected.
Any ideas on what's wrong?
BACKGROUND
I'm using AS 3.5 on MacOS Mojave, 10.14.6.
Project build.gradle
dependencies:
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50"
App build.gradle
file:
apply plugin: 'androidx.navigation.safeargs.kotlin'
dependencies {
// Navigation
def nav_version = "2.1.0"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
}