Android: How To Reset Resconfigs For Release Variant?
To make development faster, I want to do the following: android { defaultConfig { resConfigs 'en' } } My app has a lot of languages, and doing this saves significa
Solution 1:
My solution was inspired by this answer to a related question. Here's how you do it:
in app/build.gradle
// Reset `resConfigs` for release
afterEvaluate {
android.applicationVariants.all { variant ->
if (variant.buildType.name.equals('release')) {
variant.mergedFlavor.@mResourceConfiguration = null
}
}
}
This works because mResourceConfiguration
is the backing field for resConfigs
. Unfortunately, The Android Gradle DSL does not currently expose a method to reset resConfigs
, so we're forced to access the field directly using the groovy @<fieldName>
syntax. This works, even though mResourceConfiguration
is private.
WARNING: this solution is a little fragile, as the Android Gradle build tools team could change the name of that field at any time, since it is not part of the public API.
Solution 2:
Wouldn't this work?
Detect the debug build, reset the configurations and add your desired debug configuration.
applicationVariants.all { variant ->
if (variant.buildType.name == "debug") {
variant.mergedFlavor.resourceConfigurations.clear()
variant.mergedFlavor.resourceConfigurations.add("en")
}
}
Post a Comment for "Android: How To Reset Resconfigs For Release Variant?"