Ris*_*hka 7 gradle android-gradle-plugin
好的,这是我当前的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'
}
Run Code Online (Sandbox Code Playgroud)
这就是config.gradle:
def amountOfTables = 15
task howManyTables << {
println amountOfTables
}
Run Code Online (Sandbox Code Playgroud)
问题是:为什么我可以从config.gradle访问howManyTables任务.但无法访问已定义的变量?我想创建具有预定义值的自定义config.gradle.然后在我的Android应用中将它们用作变量.(如baseURL,数据类型等...).而他们,根据这些数据构建我的逻辑.无论如何,问题很明显我希望;)任何想法?
Opa*_*pal 10
因为您使用def- 来定义变量,所以它在脚本本身是本地的.尝试:
config.gradle
project.ext.amountOfTables = 15
Run Code Online (Sandbox Code Playgroud)
的build.gradle
apply from: 'config.gradle' //correct path should be here
println project.amountOfTables
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2846 次 |
| 最近记录: |