简体   繁体   中英

Kotlin multiplatform library interface's exposed types not resolved

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.

在此处输入图片说明

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:

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM