Unresolved reference for Java file in a different flavor when referencing from kotlin

后端 未结 1 1692
再見小時候
再見小時候 2021-02-09 18:39

Problem:

This question has likely been answered implicitly from all the other similar questions but I can\'t seem to get it to work.

  • If I reference a

1条回答
  •  梦如初夏
    2021-02-09 19:44

    So I had the same issue and I couldn't just change everything on the fly to Kotlin as our app is a production app and we couldn't afford the time to change to Kotlin right away - the legacy code should stay Java for now at least.

    I reported a bug to Google regarding this: https://issuetracker.google.com/issues/110100405

    And lo and behold, a Google engineer actually answered my bug report quite fast :-)

    If you don't want to read the conversation we had, I'll make it short:

    TL;DR version:

    The reason this doesn't work with Kotlin is because your packages are wrongly set up. I will bet you, that in some of your flavors you've done the same mistake as me and created directories like com.example.mypackage instead of creating the parent directory called com and then a sub-directory with the name example and then a sub-sub-directory called mypackage.

    So if your folders look com.example.mypackage change them to com with sub-directories and all should be fine.

    Another solution, which is probably the easiest is to create packages with the name com.example.mypackage in the different flavors, but this can only be done, when you've selected the flavor you want to create a package for.

    As to why, this doesn't create issues with Java, I have no idea and the Google guy didn't either, but it's probably an IntelliJ issue, which I'll report to JetBrains unless they're already aware of it.

    It's also a big issue that the Kotlin compiler just spits out a vague error saying Unresolved reference, but that's a talk for another day and another bug report or enhancement.

    0 讨论(0)
提交回复
热议问题