Thread
#multiplatform
    a

    andreasmattsson

    3 years ago
    My IDE (Android Studio) is complaining about
    Overload Resolution Ambiguity
    in the Android app modules of my MPP in cases where the disambiguity appears to only be in "comments" for the resolution of typealiases, see example snippet. It compiles fine with gradle, however it would be nice to get syntax highlighting and autocomplete etc on these types... Any suggestions for ways to resolve this?
    louiscad

    louiscad

    3 years ago
    @andreasmattsson Does it still complain if you search "New inference" in IDE settings and disable it?
    a

    andreasmattsson

    3 years ago
    @louiscad hmm not finding it with that specific search term
    Android Studio 3.4.2
    Build #AI-183.6156.11.34.5692245, built on June 27, 2019
    JRE: 1.8.0_152-release-1343-b01 amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    Windows 10 10.0
    louiscad

    louiscad

    3 years ago
    @andreasmattsson Search is not working well for that it seems. You can find the checkbox in Settings > Other Settings > Kotlin Compiler under the name "Enable new type inference algorithm for IDE analysis". It's the second checkbox.
    a

    andreasmattsson

    3 years ago
    @louiscad thanks, no immediate changes, nor after gradle resync. Should I do a full rebuild as well or no point in that?
    louiscad

    louiscad

    3 years ago
    @andreasmattsson You could reopen the project if you don't observe any changes. No need to restart the IDE.
    a

    andreasmattsson

    3 years ago
    @louiscad okay, that changed the actual message, and actually got the same problem on another statement I wasn't getting it on before, but the actual gist of it is the same:
    Cannot choose among the following candidates without completing type inference:
    public fun <T : Any> rxObservableOf(value: Float): RxObservable<Float> defined in se.sdg12.deedster.concurrency.rx
    public fun <T : Any> rxObservableOf(value: Float): RxObservable<Float> /* = Flowable<Float> */ defined in se.sdg12.deedster.concurrency.rx
    louiscad

    louiscad

    3 years ago
    @andreasmattsson The IDE still shows errors, although different, but the same project/module compiles fine?
    a

    andreasmattsson

    3 years ago
    @louiscad Still compiles fine, showing on a few more statements after switching off new inference, but still same type of statements: All of them where I'm using the expect/actual
    RxObservable
    type which i have typealiased to RxJava2's
    Flowable
    for my java/android projects
    louiscad

    louiscad

    3 years ago
    Then, you should report the bug on kotl.in/issue, preferrably showing the behavior with new type inference off as it's disabled now, and then re-enabling and showing the errors you initially had.
    a

    andreasmattsson

    3 years ago
    Hmm... Just tried something else which "solved" the issue. If I remove my "pure java" module from settings.gradle (and its corresponding sourceSet in the common module) it manages to resolve it just fine in the consuming android module (both with "new inference" off and on). The file/directory that the typealias was in was actually "shared" between both the android/pure-java versions of my common module (with
    kotlin.srcDir('src/jvmCommonMain/kotlin')
    ). @louiscad are you aware of if there are any existing issues related to IDE and including same file in multiple sourcesets, or should I still create a new one?
    louiscad

    louiscad

    3 years ago
    Oh, this kind of thing doesn't work well for now in the IDE
    a

    andreasmattsson

    3 years ago
    Okay I suspected as much.
    I previously had jvmCommon as a separate sourceSet with dependsOn from the jvmPure and android sourceSets, but that was much much worse in IDE. (barely anything was resolved in some of my consuming modules).
    louiscad

    louiscad

    3 years ago
    I'm doing it anyway to share code between other platforms. I had to hack the sourceSets plus symlinks for when the IDE syncs with Gradle
    a

    andreasmattsson

    3 years ago
    Yeah I was really hoping to avoid going the symlinks route... :S
    Know if there are any issues to track/follow for this?
    louiscad

    louiscad

    3 years ago
    I did a Kotlin script to generate the symlinks too
    Do you really need to have an android and a jvm sourceSet? Can't you have a pure jvm module, and another android module depending on the jvm module instead?
    a

    andreasmattsson

    3 years ago
    I have stuff I want to be able to access from my jvmCommon that I would like to
    expect/actual
    with different impls for pure/android (with the android versions needing access to the application context for example). I could get around it with a more dependency injection-like approach (having just an interface in the common module and "injecting" the different impls in consuming platform-specific modules) but that would require pretty significant work, whereas different
    expect/actual
    impls seemed much easier.
    louiscad

    louiscad

    3 years ago
    @andreasmattsson Here's the Kotlin script I made to create the symlinks. You can edit it to add the
    jvmCommon
    intermediate source set. It'll not delete existing directories, so it's safe to use on existing structure. Be sure to launch the script from the directory of your project's root using
    kotlin -script path/to/the/script/dir/Add-Kotlin-Targets.kts
    . https://github.com/LouisCAD/Splitties/blob/develop/scripts/Add-Kotlin-Targets.kts#L27 Then, you'll need to make an edited (and probably simpler) version of this
    buildSrc
    code I made to make the IDE point to the symlinked directories for each target: https://github.com/LouisCAD/Splitties/blob/0318f6047059ef5e97fb7bd53bd363420ad5fdf9/buildSrc/src/main/kotlin/config/KotlinSourceSetsConfig.kt#L35 It targets Kotlin/Native, but you can add support for Kotlin/JVM and Android too. After you made this and renamed the function (since it no longer targets native source sets only if at all), you can simply call it after you define the targets in your build.gradle(.kts). Note that after this is setup, symlinked files need to be manually saved (using cmd/ctrl + S), and the IDE might be a little slow to propagate files creations to other symlinked targets. Let me know if you need further help.
    a

    andreasmattsson

    3 years ago
    Thanks a lot @louiscad! I might look later closer, but for now I think I can live with just adding some flag to settings.gradle I can use to toggle between loading one or the other of the android or pure java modules (one at a time seems to work, both at once not) when working in the IDE...
    louiscad

    louiscad

    3 years ago
    Not needed, you can detect automatically when the IDE is using Gradle.
    Although you might still want that switch if you run some publishing gradle tasks from the IDE
    I mean, the toggle is probably simpler to use one or another while developing, and both when building, but I personally prefer being able to use both while developing, and just have to use command line for publishing (instead of using IDE and launching tasks from the Gradle tool window).