简体   繁体   中英

Can't access commonMain multiplatform classes from a jvm-only module

I have a project with following structure:

  • multiplatformmodule - contains a single kotlin class SomeMultiPlatformClass
  • jvmmodule - a pure jvm module which depends on multiplatformmodule

The problem is that within the jvmmodule I can't access any class from multiplatformmodule when running a test. I get java.lang.NoClassDefFoundError: com/example/multiplatform/multiplatformmodule/SomeMultiPlatformClass . IDE (Anroid Studio) also marks this class as unresolved. It builds, however, when the multplatformmodule classes are accessed from another multiplatform module.

Much more can be seen in the example project https://github.com/micHar/kmm-dependency-issues/tree/master .

I cloned your repo and opened it with Intellij 2020.3.1 and it seems to resolve SomeMultiPlatformClass fine. I tried to run tests from the IDE, which didn't work for different reasons. When I changed the @Test to point to kotlin.test.Test the IDE also ran the tests fine.

在此处输入图像描述

https://github.com/kpgalligan/kmm-dependency-issues

This is clearly an Android Studio bug. Running your project with gradle, ie ./gradlew test will run the test ( SomeJvmTest ) just fine.

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