2

I'm using Kotlin for the first time to develop an Android app. Currently I'm working on a library module ("data") inside my project, separate from the main app module:

> [Root directory]
    > app
        > [...]
    > data
        > src
            > debug
                > kotlin 
                    > com.domain.app
                        > [...]
            > main
                > kotlin 
                    > com.domain.app
                        > [...]
            > release
                > kotlin 
                    > com.domain.app
                        > [...]

I've come across a snag: whenever a file inside data.src.main references a file inside data.src.debug, the build process fails with the message "Unresolved reference: [class name]". However, it doesn't fail when I reference files inside data.src.release. In both cases I've triple checked the syntax, directories, and build variants.

I haven't modified the debug or release build types inside my build.gradle files - I'm using whatever their default settings are. My source sets are:

android {
  ...
  sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
    debug.java.srcDirs += 'src/debug/kotlin'
    release.java.srcDirs += 'src/release/
  }
}

The module is using the 'com.android.library' and 'kotlin-android' plugins. All the files I've tested with so far have been Kotlin files, though I don't know if this is a Kotlin issue or something else. Kotlin has otherwise been behaving.

I figured this might be caused by the default debug settings, but I also testing app.src.main referencing app.src.debug, and that works correctly despite using the same default settings.

stphven
  • 85
  • 1
  • 8

2 Answers2

4

I've determined that my issue is caused by this bug in the Android Gradle plugin: https://code.google.com/p/android/issues/detail?id=52962

From the documentation: "By default a library only publishes its release variant." While this issue is public knowledge, I found it surprisingly difficult to identify - it's one of those "you either know about it or you don't" gotchas.

Anyway, know that I know about it I've been able to resolve it. See the comments in the link for solutions.

stphven
  • 85
  • 1
  • 8
0

If you're having a problem with debugging Kotlin code check out my answer here https://stackoverflow.com/a/48270306/1502079.

In my case the issue was a caused by Instant run.

vovahost
  • 34,185
  • 17
  • 113
  • 116