我已经成功使用gradle脚本编写了我的gradle.propreties文件,我将分享我的代码,
build.gradle:
afterEvaluate {
processDebugGoogleServices.dependsOn switchToDebug
processReleaseGoogleServices.dependsOn switchToRelease
}
String base = "URL"
def slurper = new JsonSlurper()
def app_data = slurper.parseText(base.toURL().text)
def FileWriter mFile = new FileWriter(".........../gradle.properties")
现在我面临一个问题,我在属性文件中编写的键和值对在默认配置中使用 for exp - applicationId,versionCode,versionname等。在编写我的gradle.property文件时,android的默认配置和我一起执行 任务,由于系统无法找到applicationId,versionCode,versionname等。
build.gradle:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "${app_id}"
minSdkVersion 15
targetSdkVersion 23
versionCode java.lang.Integer.parseInt("${version_code}")
versionName "${version_name}"
}
Error:(51, 0) Could not get unknown property 'app_id' for ProductFlavor_Decorated{name=main, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=null, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.ProductFlavor.
<a href="openFile:.........../app/build.gradle">Open File</a>
答案 0 :(得分:1)
要解决此问题,只需在根目录中创建另一个文件other.gradle。将您的脚本放在该文件中,就像
一样task abc {
String base = "URL"
def slurper = new JsonSlurper()
def app_data = slurper.parseText(base.toURL().text)
def FileWriter mFile = new FileWriter(".........../gradle.properties")
}
现在可以使用-b选项执行gradle命令。例如
gradle -b other.gradle abc
现在正常运行您的项目。