Android: How to reset resConfigs for release option?

To speed up development, I want to do the following:

android { defaultConfig { resConfigs "en" } } 

There are many languages ​​in my application, and this saves significant development time. However, I do not want to release a version with this set. Unfortunately, resConfigs not available for product tastes or build types, so I cannot install it in debug {} , for example.

How can I automatically exclude resConfigs from release options? I do not want to forget to comment on this line of code when creating for release.

+1
source share
2 answers

My decision was inspired by this answer to the corresponding question. Here's how you do it:

in the application /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 a support field for resConfigs . Unfortunately, the DSL in Android Gradle does not currently set the reset resConfigs method, so we have to directly access the field using the groovy @<fieldName> syntax. This works, although mResourceConfiguration is private.

WARNING : this solution is a bit fragile, as the Android Gradle tool development team can change the name of this field at any time, because it is not part of the public API.

0
source

Does this work?

Define the debug configuration, reset the configuration and add the desired debug configuration.

 applicationVariants.all { variant -> if (variant.buildType.name == "debug") { variant.mergedFlavor.resourceConfigurations.clear() variant.mergedFlavor.resourceConfigurations.add("en") } } 
+1
source

Source: https://habr.com/ru/post/975017/


All Articles