简体   繁体   English

错误:build.gradle.kts 中的“未解决的参考:versionCode”

[英]Error: "Unresolved reference: versionCode" in build.gradle.kts

I'm trying to add a new module (library module) to my project but in build.gradle.kts (for library module) I have this error:我正在尝试向我的项目添加一个新模块(库模块),但在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 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"
    }
}

I would be grateful for any help我将不胜感激任何帮助

versionCode and versionName are meaningless in a library module. versionCodeversionName在库模块中没有意义。 Use them only in the application module.仅在应用程序模块中使用它们。

In the long term, Google plans to remove them from the DSL altogether in some version of Android Gradle Plugin:从长远来看,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.在 Android Gradle 插件的未来版本中, versionNameversionCode属性也将从库的 DSL 中删除。

( source ) 来源

If you are on an early non-stable version of AGP, you might have this change already.如果您使用的是 AGP 的早期非稳定版本,您可能已经进行了此更改。 The code templates in Android Studio are not always in sync with the tooling changes. Android Studio 中的代码模板并不总是与工具更改同步。

Remove versionCode and versionName from library module and check again从库模块中删除 versionCode 和 versionName 并再次检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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