gpt4 book ai didi

android - Gradle 属性中的引用属性

转载 作者:行者123 更新时间:2023-12-02 16:52:12 24 4
gpt4 key购买 nike

我的gradle.properties.kts文件具有以下内容:

build_version=develop
build_version_code=2
include_vas=false

在我的build.gradle.kts中,如下所示:

plugins {
id(Plugins.androidApplication)
kotlin(Plugins.kotlinAndroid)
kotlin(Plugins.kotlinExtensions)
kotlin(Plugins.kapt)
}


android {
compileSdkVersion(Configs.compileVersion)
defaultConfig {
applicationId = Configs.applicationId
minSdkVersion(Configs.minSdkVersion)
targetSdkVersion(Configs.targetSdkVersion)
testInstrumentationRunner = Configs.testInstrumentationRunner
versionCode =
}


buildTypes{

}
repositories {
flatDir {
dirs("libs")
}
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.arr"))))
implementation(Libs.stdLib)
implementation(Libs.sunmiui)
implementation(Libs.slf4j)
implementation(Libs.appCompact)
implementation(Libs.otpView)
implementation(Libs.vectordrawableAnimated)
implementation(Libs.materialComponents)
implementation(Libs.recyclerView)
implementation(Libs.constraintLayout)
implementation(Libs.junit)
implementation(Libs.testRunner)
implementation(Libs.expressoCore)
implementation(Libs.lifecyleExtensions)
implementation(Libs.lifecyleCompiler)
implementation(Libs.roomRuntime)
implementation(Libs.databindingCompiler)
implementation(Libs.rxjava)
implementation(Libs.rxjavaAndroid)
implementation(Libs.glide)
implementation(Libs.glideCompiler)
implementation(Libs.gson)
implementation(Libs.joda)
implementation(Libs.countrycodePicker)
implementation(Libs.timber)
implementation(Libs.daggerandroidSupport)
implementation(Libs.daggerandroidProcessor)
}

我正在将当前的 gradle 脚本转换为 kotlin DSL。我当前面临的挑战是在defaultConfig中:

android {
compileSdkVersion(Configs.compileVersion)
defaultConfig {
applicationId = Configs.applicationId
minSdkVersion(Configs.minSdkVersion)
targetSdkVersion(Configs.targetSdkVersion)
testInstrumentationRunner = Configs.testInstrumentationRunner
versionCode =
}

我指的是gradle.properties中定义的versionCode。下面的代码是在转换之前是如何完成的。

defaultConfig
{

multiDexEnabled true
applicationId "jfjfjrjrjr.comn.jejeu"
minSdkVersion 24
targetSdkVersion 28
versionCode build_version_code as Integer
versionName build_version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

如何在 Kotlin 中执行此操作

最佳答案

v0.16.3 Gradle Kotlin DSL(包含在 Gradle v4.7 中)的一部分可以使用属性委托(delegate)来表示在 gradle.properties 中声明的值,如下所示:

val yourVariable: TypeOfYourVariable by project

您的示例如下所示:

val build_version_code: String by project

defaultConfig {
...
versionCode = build_version_code
...
}

关于android - Gradle 属性中的引用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56363135/

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