Shared generated Java sources


#1

Hi.
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…)
So…
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:


#2

I’m created sample GIT repository with this problem: https://github.com/akvast/kotlin-problem

mobile.gradle:

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

wear.gradle:

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?


#3

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


#4

Thank you. Now everything works.