我已经使用 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")
现在我面临一个问题,我在属性文件中写入的键和值对在 exp - applicationId 、 versionCode 、 versionname 等的默认配置中使用。在编写我的 gradle.property 文件时,android 的默认配置与我一起执行tasks ,由于系统无法找到 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>