1
votes

We have a multi-module android project, which we began to refactor to a kotlin-multiplatform project with several modules to share with our iOS app.

Our multiplatform project currently has 4 modules: domain, presentation, data and shared-app. The shared-app module depends on the other three modules and this is the module which is imported into the old android project. We merge the modules into a single one to generate only a single Framework for the iOS project.

Both projects build sucessfully. But if we retrieve an interface instance which is defined in the shared-app module which uses types from the submodules, the IDE shows [ERROR : SomeType] for its return types.

enter image description here

In our old android projects settings.gradle, we used includeBuild(mpp-project) and created a dependency substitution for the shared-app module in the mpp-project.

enableFeaturePreview("GRADLE_METADATA")

includeBuild("mpp-project") {
    dependencySubstitution {
        substitute(module("our.package.name:shared")).with(project(":shared-app"))
    }
}

On the other hand, all of our exposed and transitively imported type can be instantiated in the old android project, even from the submodules. (for example I can instatiate SomeType and it resolves)

Gradle project structure:

oldAndroidRootProject
├─myApp (import implementation of all androidModules and mppFramework)
│  └─build.gradle
├─androidModule1
│  └─build.gradle
├─androidModule2
│  └─build.gradle
├─androidModule3
│  └─build.gradle
│
├─myMppRootProject
│   ├─mppFramework (depends on mppModuleXs and dependencies are declared as api(":mppModuleX"))
│   │   └─build.gradle
│   ├─mppModule1
│   │   └─build.gradle
│   ├─mppModule2
│   │   └─build.gradle
│   ├─mppModule3
│   │   └─build.gradle
│   ├─mppModule4
│   │   └─build.gradle
│   ├─build.gradle
│   └─settings.gradle (uses includeBuild("myMppRootProject"))
├─build.gradle
└─settings.gradle (uses includeBuild("myMppRootProject"))

If I check the mppFramework modules source, when the androidRoot project was opened I see this:

enter image description here

1
I've just found an issue on the issue tracker, which might cause this behavior: youtrack.jetbrains.com/issue/KT-30285 - Agócs Tamás
For temporary workaround, we created a separate module, which pulls together all the source files into one fat module, but we would really like to keep our modularized mpp project, so this is only a temporary hack. - Agócs Tamás

1 Answers

1
votes

If I can paraphrase:

   -------
   - ios -
   -------
      |
   ----------
   - shared - ---------
   ----------          \
       |      \         \
   -------- ---------- ----------------
   - data - - domain - - presentation -
   -------- ---------- ----------------

If shared is the single point of entry, it should expose the dependent types through the header. The tricky part of this kind of stuff is when you want something from, say, domain, that isn't included in a public call in shared. If that's not the case, what you're doing should work.

It would be helpful if you posted the build config, so we can see how dependencies are configured. Also, does this work on the command line? Sometimes the IDE isn't working but the build is OK.

Also, is this Intellij or Android Studio, and what version? Intellij tends to be more up-to-date with regards to KMP.