I need to define a method in build.gradle
to define BuildConfigFields
. What i have tried is below .
defaultConfig {
initializeBuildConfig()
applicationId com.terser
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ext.initializeBuildConfig = {->
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(file('config.properties')))
def properties_appName = versionProps['APP_NAME']
manifestPlaceholders = [appname:properties_appName]
def properties_authkey=versionProps['AUTH_KEY']
buildConfigField "String", "AUTH_KEY", "\"$properties_authkey\""
}
}
But its not working giving the error .
Could not find method initializeBuildConfig() for arguments [] on DefaultConfig_Decorated{name=main, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=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={appname=invite}, mWearAppUnbundled=null} of type com.android.build.gradle.internal.dsl.DefaultConfig.
Can anyone help me ? I would like to know how can i define a method in same block and also in other blocks and call it. Also how can i return a value from a method
?
I have already checked out How to define and call custom methods in build.gradle. The answer there is seems correct but i could not grab the concept from the answers given in the above link . I have tried to implement the same but getting the above error.