gpt4 book ai didi

android - 错误 : "Unresolved reference: versionCode" in build. gradle.kts

转载 作者:行者123 更新时间:2023-12-04 23:36:09 27 4
gpt4 key购买 nike

我正在尝试将一个新模块(库模块)添加到我的项目中,但在 build.gradle.kts 中(对于库模块)我有这个错误:

org.gradle.internal.exceptions.LocationAwareException: Build file ' ... /build.gradle.kts' line: 13
Script compilation errors:

Line 13: versionCode = 1
^ Unresolved reference: versionCode

Line 14: versionName = "1.0"
^ Unresolved reference: versionName

.
.
.

Caused by: ScriptCompilationException( ... )
build.gradle.kts
plugins {
id("com.android.library")
id("kotlin-android")
}

android {
compileSdk = 30
buildToolsVersion = "30.0.3"

defaultConfig {
minSdk = 21
targetSdk = 30
versionCode = 1 //error: Unresolved reference
versionName = "1.0" //error: Unresolved reference

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
我将不胜感激

最佳答案

versionCodeversionName在库模块中是没有意义的。仅在应用程序模块中使用它们。
从长远来看,Google 计划在某些版本的 Android Gradle 插件中将它们从 DSL 中完全删除:

In a future version of Android Gradle plugin, the versionName and versionCode properties will also be removed from the DSL for libraries.


( source)
如果您使用的是 AGP 的早期非稳定版本,您可能已经进行了此更改。 Android Studio 中的代码模板并不总是与工具更改同步。

关于android - 错误 : "Unresolved reference: versionCode" in build. gradle.kts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67803478/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com