Skip to content

Instantly share code, notes, and snippets.

@tiwiz
Created June 6, 2015 08:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiwiz/b5fac29f4bacc3dfb0c9 to your computer and use it in GitHub Desktop.
Save tiwiz/b5fac29f4bacc3dfb0c9 to your computer and use it in GitHub Desktop.
Implementing Crashlytics on a multiflavour and multi-key environment
final File fabricFile = file("fabric.properties")
afterEvaluate {
android.applicationVariants.all { variant ->
final String variantName = variant.getName().capitalize()
final Task targetTask = tasks["process${variantName}Manifest"]
if (fabricTask != null) {
final Task generateFabricFile = task("generateFabricFile$variantName") {
doLast {
String fabricApiSecret = 'verySecretApiSecretForEveryoneGuessItsNotThatSecret'
String fabricApiKey = 'veryKeyApiKeyForEveryone'
if (variantName.equalsIgnoreCase("DifferentClientDebug") || variantName.equalsIgnoreCase("DifferentClientRelease")) {
fabricApiSecret = 'verySecretApiSecretForDifferentClient'
fabricApiKey = 'veryKeyApiKeyForDifferentClient'
}
if (fabricFile.exists()) {
println "Deleting previous configuration File for Fabric (variant: $variantName)"
fabricFile.delete()
}
println '*** FABRIC DATA ***'
println "apiSecret=$fabricApiSecret"
println "apiKey=$fabricApiKey"
println '*******************'
def commentMessage = "Autogenerated Fabric properties for Crashlytics"
ant.propertyfile(file: fabricFile, comment: commentMessage) {
entry(key: "apiSecret", value: fabricApiSecret)
entry(key: "apiKey", value: fabricApiKey)
}
}
}
targetTask.dependsOn generateFabricFile
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment