[FIXED] Android Gradle 2.5 how to get resConfigs to work

Issue

To use the latest NDK support in Android Studio you have to use Gradle 2.5.
http://tools.android.com/tech-docs/new-build-system/gradle-experimental

Which introduces a new syntax. eg. buildToolsVersion “23.0.1” becomes buildToolsVersion = “23.0.1”

For resConfigs pre Gradle 2.5 you write it:

 defaultConfig {
        ...
        resConfigs "en", "fr"
        }

But with 2.5, I could not find a way to write a comma delimited strings.

Even when I tried with one string

defaultConfig.with  {
        ...
        resConfigs = "fr"
        }

I got this error
Error:No such property: resConfigs for class: com.android.build.gradle.managed.ProductFlavor

I need this as AppCompat has translations for many languages which I am not supporting ATM.

Edit Updates
I figured how to enter a list of strings in the new format e.g

resConfigs = ["fr", "es"]

But still I get the error of it not recognising resConfigs

when running with ./gradlew –stacktrace assembleDebug here is the output

 problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
   > No such property: resConfigs for class: com.android.build.gradle.managed.ProductFlavor

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
    at org.gradle.execution.TaskNameResolver.selfClosedTasksNode(TaskNameResolver.java:116)
    at org.gradle.execution.TaskNameResolver.hasTask(TaskNameResolver.java:128)
    at org.gradle.execution.TaskNameResolver.access$100(TaskNameResolver.java:38)
    at org.gradle.execution.TaskNameResolver$MultiProjectTaskSelectionResult.collect(TaskNameResolver.java:195)
    at org.gradle.execution.TaskNameResolver$MultiProjectTaskSelectionResult.collect(TaskNameResolver.java:203)
    at org.gradle.execution.TaskNameResolver$MultiProjectTaskSelectionResult.collectTasks(TaskNameResolver.java:191)
    at org.gradle.execution.TaskNameResolver.selectWithName(TaskNameResolver.java:61)
    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:87)
    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:75)
    at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:42)
    at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:44)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:51)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$000(DefaultBuildConfigurationActionExecuter.java:25)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter$1.proceed(DefaultBuildConfigurationActionExecuter.java:57)
    at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:47)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:51)

Solution

Here’s what works for me:

| gradle-experimental version   | Gradle version | resConfigs usage                  |
|-------------------------------|----------------|-----------------------------------|
| 0.2.0                         | 2.5            | resourceConfigurations = ["fr"]   |
| 0.3.0-alpha5                  | 2.6            | resourceConfigurations = ["fr"]   |
| 0.6.0-alpha5                  | 2.10           | resourceConfigurations << "fr"    |

The thing I don’t get is, I looked up the source of gradle-core-1.4.0-beta4 which is a dependency for gradle-experimental:0.3.0-alpha5 and the DSL for productFlavor does contain code for resConfig and resConfigs. In com.android.build.gradle.internal.dsl.ProductFlavor.java

public void resConfigs(@NonNull String... config) {
    addResourceConfigurations(config);
}

I’m unsure why it isn’t being picked up correctly.

Answered By – RaGe

Answer Checked By – Katrina (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published