Trying to add dependency to Android processResources

I’m trying to run a script to generate my strings.xml files just before the resource files are processed. I’ve seen the answer to this question:

http://forums.gradle.org/gradle/topics/how_to_define_a_preprocessing_task_for_android_build

But I get the error: Could not find property ‘processResources’ on com.android.build.gradle.AppExtension_Decorated@4a6a412c.

This is what I’ve got:

task generateLocalizedStrings(type:Exec) {

workingDir ‘…/…/…/localization/’

commandLine ‘python’, ‘localizationScript.py

}

project.afterEvaluate {

processResources.dependsOn(“generateLocalizedStrings”)

}

I’ve also tried:

applicationVariants.all { variant ->

variant.processResources.dependsOn(“generateLocalizedStrings”)

}

The second way is the way that the Gradle user guide (http://tools.android.com/tech-docs/new-build-system/user-guide) Tells you to do it.

However, it appears that part of the guide is broken as of the 1.0 release. In particular, we had to do

variant.outputs[0].process… to make it work.

I have no clue why their are multiple outputs, or what may be missed if you only do it on [0]. Regardless, the docs are apparently out of date for the current release. The correct place to report (or discuss) that would be over at the adt-dev list (https://groups.google.com/forum/#!forum/adt-dev)

As a side note: The Gradle user guide is the documentation for Gradle in general. The documentation page you are pointing out is the documentation of the Gradle Android plugin.

My bad, I was meaning to copy the (less than ideal) name from the android docs, which is “Gradle Plugin User Guide”

Thanks for the help! I actually went with

applicationVariants.all { variant ->

variant.outputs.each { output ->

output.processResources.dependsOn(“generateLocalizedStrings”)

}

}