Android 项目无法看到 commonMain 中的代码。

huangapple go评论127阅读模式
英文:

Android project doesn't see code in commonMain

问题

I've tested this project out link and I've then created a shared module in my existing project (normal Android Project, not KMM enabled). I've tried both creating the module from scratch and also importing the module from the project above.

It seems that I can't access the Shared class from commonMain from my Android Project code, unless I move the class to main. In the above project, it works just fine having it in commonMain.

I'm guessing I'm doing something wrong, but ... I have no idea what.

I'd copy-paste the build.gradle from the shared module, but it's exactly as the from from the project above link

Any ideas on what else I need to setup/enable?

英文:

I've tested this project out https://github.com/touchlab/KMMBridgeSampleKotlin
and I've then created a shared module in my existing project (normal Android Project, not KMM enabled). I've tried both creating the module from scratch and also importing the module from the project above.

It seems that I can't access the Shared class from commonMain from my Android Project code, unless I move the class to main. In the above project, it works just fine having it in commonMain.

I'm guessing I'm doing something wrong, but ... I have no idea what.

I'd copy-paste the build.gradle from the shared module, but it's exactly as the from from the project above https://github.com/touchlab/KMMBridgeSampleKotlin/blob/main/shared/build.gradle.kts

Any ideas on what else I need to setup/enable?

答案1

得分: 1

请检查以下几点:

确保在项目设置中包括共享模块。要做到这一点,打开你项目中的 settings.gradle 文件并添加以下行:

include(":shared")

这将确保共享模块被包括在项目中。

检查你的应用模块的 build.gradle 文件中的依赖项。确保你已将共享模块添加为依赖项:

implementation(project(":shared"))

这将确保应用模块可以访问共享模块中的类。

确保共享模块的 build.gradle 文件中的 commonMain 源集已正确配置。

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation(...)
        }
    }
}
英文:

A few things you can check:

Make sure that the shared module is included in the project settings. To do this, open the settings.gradle file in your project and add the following line:

include(":shared")

This will ensure that the shared module is included in the project.

Check the dependencies in your build.gradle file for the app module. Make sure that you have added the shared module as a dependency:

implementation(project(":shared"))

This will ensure that the app module has access to the classes in the shared module.

Make sure that the commonMain source set is configured correctly in the shared module's build.gradle file.

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation(...)
        }
    }
}

答案2

得分: 1

我只需更新我的Gradle依赖项。我将com.android.tools.build:gradle更新到7.x以上的某个版本,还将Kotlin插件更新到更高的版本,将com.google.gms:google-services更新到4.3.x,现在它可以正常工作。

英文:

I simply had to update my gradle dependencies. I updated the com.android.tools.build:gradle to something above 7.x and also kotlin plugin to a higher version, com.google.gms:google-services to 4.3.x and now it works.

huangapple
  • 本文由 发表于 2023年3月7日 19:03:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661164.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定