我已从Ant脚本迁移到gradle构建脚本。但我不知道如何在gradle构建脚本中获取包名称或applicationId。
答案 0 :(得分:1)
project.afterEvaluate {
project.android.applicationVariants.all { variant ->
def applicationId = [variant.mergedFlavor.applicationId, variant.buildType.applicationIdSuffix].findAll().join()
...
}
}
或在foo.gradle中定义一个:
// foo.gradle
def appId = 'com.example.bar'
ext.appId = appId
// build.gradle
apply from: './foo.gradle'
...
defaultConfig {
...
applicationId appId
}
// other.gradle you want
apply from: './foo.gradle'
...
task example {
println(appId)
}