Android Studio : How to access project level compileSdkVersion and targetSdkVersion in Kotlin Multiplatform shared module build. gradle.kts?

标签 android android-studio build.gradle gradle-kotlin-dsl kotlin-multiplatform

我正在尝试将 KMM 共享模块添加到我现有的 Android Studio 项目中。我想在共享模块中使用项目级别 build.gradle 中的compileSdkVersion和targetSdkVersion,但我似乎无法使用它。

这是共享模块build.gradle.kts的代码 fragment :

android {
    compileSdkVersion(30) // I want to use a project-wide variable here instead of '30'
    defaultConfig {
        minSdkVersion(23) // And here
        targetSdkVersion(30) // And here
    }
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
}

我该怎么做?

最佳答案

您可以在 buildSrc 中创建一个 Dependency/Versions 文件来指定可由多个模块重用的版本。

有关示例,请参阅 https://github.com/joreilly/PeopleInSpace/blob/master/buildSrc/src/main/java/Dependencies.kt

关于Android Studio : How to access project level compileSdkVersion and targetSdkVersion in Kotlin Multiplatform shared module build. gradle.kts?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65624486/

相关文章:

Android:FaceDetector 不工作。 findface 始终检测零面;

android - 尽管数据没有改变,但一些 fragment 观察者在从返回堆栈弹出后触发

Android - ActivityUnitTestCase - 测试总是通过

android - 取消停靠后,Android Studio 中的 "Docked Mode"设置中没有 "Preview"选项

android - Gradle错误Android Studio 'AsmBackedClassGenerator'

android - 我如何在 "build.gradle"应用程序中分离库版本

android - 错误 :Could not find property 'assembleDebug' on project ':app'

tomcat - 更改 gradle-tomcat-plugin 根 Web 应用程序目录

android - 每次 Activity 都开始创建该类的新对象吗?

java - 无法解析 ':app@debug/compileClasspath'的依赖项:gradle同步时无法解决com.google.android.things:androidthings:1.0错误