Skip to content

Instantly share code, notes, and snippets.

@luongvo
Forked from alexsinger/build.gradle
Created April 27, 2017 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luongvo/b61eef89af3b2acd5f3c59062c74d0c3 to your computer and use it in GitHub Desktop.
Save luongvo/b61eef89af3b2acd5f3c59062c74d0c3 to your computer and use it in GitHub Desktop.
Separate Crashlytics reporting for debug and release buildTypes using a Gradle build
// The following code allows an app to report Crashlytics crashes separately
// for release and debug buildTypes when using Gradle. This code should be inserted
// into the specified locations within your build.gradle (Module:app) file
// The buildTypes { } block should be inserted inside the android { } block
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ext.crashlyticsApiSecret = "release api secret"
ext.crashlyticsApiKey = "release api key"
}
debug {
ext.crashlyticsApiSecret = "debug api secret"
ext.crashlyticsApiKey = "debug api key"
}
}
// The following code can be inserted at the bottom of your build.gradle file
import com.crashlytics.tools.utils.PropertiesUtils
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", variant.buildType.ext.crashlyticsApiSecret)
println "...copying apiKey for ${variant.name}"
properties.put("apiKey", variant.buildType.ext.crashlyticsApiKey)
PropertiesUtils.injectPropertyInFile(crashlyticsProperties, properties, "")
}
generateResourcesTask.dependsOn generatePropertiesTask
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment