gpt4 book ai didi

gradle - 如何从另一个gradle文件访问值?

转载 作者:行者123 更新时间:2023-12-04 11:04:56 26 4
gpt4 key购买 nike

好的,这是我当前的build.gradle:

apply plugin: 'com.android.application'
apply from: '../config.gradle'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId ""
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
resValue "int", "amountOfTables", amountOfTables
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
howManyTables.execute()
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.pnikosis:materialish-progress:1.4'
}

这就是config.gradle:
def amountOfTables = 15

task howManyTables << {
println amountOfTables
}

问题是:
为什么我可以从config.gradle中访问howManyTables任务。但是无法访问已定义的变量吗?我想用预定义的值创建自定义config.gradle。然后将它们用作我的Android应用程序中的变量。 (如baseURL,数据类型等)。然后,根据这些数据构建我的逻辑。无论如何,我希望这个问题很清楚;)有什么想法吗?

最佳答案

因为您使用def定义了变量-所以它在脚本本身中是本地的。尝试:

config.gradle

project.ext.amountOfTables = 15

build.gradle
apply from: 'config.gradle' //correct path should be here
println project.amountOfTables

关于gradle - 如何从另一个gradle文件访问值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28628845/

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