I'm using NavigationComponent
in my app and now I'm facing following problem:
I have 2 different flavors (free and paid version) which are using the same navigation.xml located in the main package. When I want to run e.g. the paid variant it failed with these errors in the generated directions file:
e: AndroidStudioProjects/foo/app/build/generated/source/navigation-args/paid/debug/de/dk/fc/ui/knowledge/KnowledgeFragmentDirections.kt: (5, 24): Unresolved reference: paid
e: AndroidStudioProjects/foo/app/build/generated/source/navigation-args/paid/debug/de/dk/fc/ui/knowledge/KnowledgeFragmentDirections.kt: (14, 41): Unresolved reference: R
Here is a snippet of my navigation.xml
<fragment
android:id="@+id/fragment_knowledge"
android:name="de.dk.fc.ui.knowledge.KnowledgeFragment"
tools:layout="@layout/fragment_knowledge">
<action
android:id="@+id/action_fragmentKnowledge_to_fragmentInfo"
app:destination="@id/fragment_info" />
</fragment>
I also added these lines of code to my build.gradle
file:
sourceSets {
getByName("main").java.srcDirs("build/generated/source/navigation-args")
}
What I've tried:
Do you have any ideas how to solve this problem?
Did you upgrade to the Android Gradle Plugin version 7.2.0 and ran the recommended before this error occurred? One of them is to move the package name from the Android manifest file to the build files.
It seems that this change causes difficulties with the navigation component when having different applicationIds in the project (as you probably have for your different flavours).
Simply put the package name back into the manifest file and it should work again. This should fix it at least temporarily until the navigation component can handle the changes.