I have an Android app that has the following products:
productFlavors {
local {
}
development {
}
production {
}
}
then at the bottom of mine 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 am trying to install api secret/keyfor crashlytics, but I need to install them depending on the taste of the product I create.
properties.put("apiSecret", WHAT_GOES_HERE)
properties.put("apiKey", WHAT_GOES_HERE)
How can I set / get these variables?
Update # 1
I added the following to 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 file build.gradleI 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 does not give me:
Error: (334, 1) Execution failed for task ': app: fabricGeneratePropertiesDevelopmentDebug'. Could not find the 'BuildConfig' property for task ': app: fabricGeneratePropertiesDevelopmentDebug'.