Shared generated Java sources

I have mobile and wear modules in one project.
Both of them use generated Java classes at path ‘src/main/jni/library/src/gen/java’ for app module and ‘…/app/src/main/jni/library/src/gen/java’ for wear module. (Same folder…)
Kotlin doesn’t want to use this classes in app module while they are used in wear module.

I think this because Android Studio mark this folder only as wear sources root:

I’m created sample GIT repository with this problem:


sourceSets.main {
    java.srcDirs += 'src/shared/java'


sourceSets.main {
    java.srcDirs += '../mobile/src/shared/java'

Mobile MainActivity.kt:

If i remove additional srcDirs from wear.gradle error was gone.

How i can use shared (generated) Java classes in both modules?

Have you considered making a separated module with shared code and include it as a dependency to the other two modules?

Thank you. Now everything works.