Friday, 28 August 2020

SafeArgs not generating Directions / Args classes on a multi module project

I created an empty project to try out the Navigation component. I wanted to see how it would behave with a multi module project (one common module with the majority of the dependencies, plus modules that would hold different parts of the app, and the :app module that would implement all of the modules).

The top level gradle file has the dependency like so:

dependencies {
    classpath "com.android.tools.build:gradle:3.6.1"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-alpha04"
}

The common module has these dependencies (among others):

dependencies {
    …
    api "androidx.navigation:navigation-fragment-ktx:2.2.1"
    api "androidx.navigation:navigation-ui-ktx:2.2.1"
    api "androidx.navigation:navigation-dynamic-features-fragment:2.3.0-alpha04"
    …
}

And absolutely all the modules have this plugin applied on top:

apply plugin: "androidx.navigation.safeargs.kotlin"

Now, each "ui module" has fragments in it, and only the :app one implements a main_graph.xml that references to them. An example would be:

<fragment
    android:id="@+id/registerFragment"
    android:name="example.register.RegisterFragment"
    android:label="RegisterFragment">
    <action
        android:id="@+id/action_registerFragment_to_loginFragment"
        app:destination="@id/loginFragment" />
</fragment>

After all this is finished, a good Clean Project + Rebuild Project is done.

To me, this makes sense. However, when I try calling the theoretically auto generated file RegisterFragmentDirections is not there, not in the specific sub module, not in the main one. The NavDirections can be found (so the dependencies somehow are working), but not the generated ones.

I've tried implementing all the dependencies in each module, rolling back the navigation version to the previous alpha ones… no success.



from SafeArgs not generating Directions / Args classes on a multi module project

No comments:

Post a Comment