I have an android application that has the following product flavors:
productFlavors {
local {
}
development {
}
production {
}
}
then have the following at the bottom of my build.grade
:
File crashlyticsProperties = new File("${project.projectDir.absolutePath}/fabric.properties")
android.applicationVariants.all { variant ->
def variantSuffix = variant.name.capitalize()
def generateResourcesTask = project.tasks.getByName("fabricGenerateResources${variantSuffix}")
def generatePropertiesTask = task("fabricGenerateProperties${variantSuffix}") << {
Properties properties = new Properties()
properties.put("apiSecret", WHAT_GOES_HERE)
properties.put("apiKey", WHAT_GOES_HERE)
PropertiesUtils.injectPropertyInFile(crashlyticsProperties, properties, "")
}
generateResourcesTask.dependsOn generatePropertiesTask
}
I'm trying to set the api secret/key
for crashlytics
but I need to be able to set these depending on what product flavor I'm building.
properties.put("apiSecret", WHAT_GOES_HERE)
properties.put("apiKey", WHAT_GOES_HERE)
How can I set/get these variables?
Update #1
I've added the following to my build.gradle
productFlavors {
local {
buildConfigField "String", "CRASHLYTICS_API_SECRET", "1234"
buildConfigField "String", "CRASHLYTICS_API_KEY", "1234"
}
development {
buildConfigField "String", "CRASHLYTICS_API_SECRET", "1234"
buildConfigField "String", "CRASHLYTICS_API_KEY", "1234"
}
production {
buildConfigField "String", "CRASHLYTICS_API_SECRET", "1234"
buildConfigField "String", "CRASHLYTICS_API_KEY", "1234"
}
}
Then at the bottom of the build.gradle
file I have:
File crashlyticsProperties = new File("${project.projectDir.absolutePath}/fabric.properties")
android.applicationVariants.all { variant ->
def variantSuffix = variant.name.capitalize()
def generateResourcesTask = project.tasks.getByName("fabricGenerateResources${variantSuffix}")
def generatePropertiesTask = task("fabricGenerateProperties${variantSuffix}") << {
Properties properties = new Properties()
println "...copying apiSecret for ${variant.name}"
properties.put("apiSecret", BuildConfig.CRASHLYTICS_API_SECRET)
println "...copying apiKey for ${variant.name}"
properties.put("apiKey", BuildConfig.CRASHLYTICS_API_KEY)
PropertiesUtils.injectPropertyInFile(crashlyticsProperties, properties, "")
}
generateResourcesTask.dependsOn generatePropertiesTask
}
This however does not compile and gives me:
Error:(334, 1) Execution failed for task ':app:fabricGeneratePropertiesDevelopmentDebug'. Could not find property 'BuildConfig' on task ':app:fabricGeneratePropertiesDevelopmentDebug'.