https://kotlinlang.org logo
Title
m

max

08/14/2018, 12:59 AM
Hi there, please help me understand how to configure
processResources
correctly. What I’m trying to do is: I have a file:
src/main/res/xml/file.xml
which has a string like
<external-path name="my_images" path="Android/data/{$appId}/files/Pictures/" />
. Now I’m trying to replace appId token in gradle build script as follows:
tasks {
    withType<ProcessResources> {
        filesMatching("${projectDir}/src/main/res/xml/file.xml") {
            val tokens = mapOf("appId" to "myApplicationId")
            expand(tokens)
        }
        outputs.upToDateWhen { false }
    }
}
But that seems not working. Build finishes without errors, but if I open that xml file after artifact is produced, the template is not fulfilled. I spend on this a almost a day, please help me understand what’s wrong here.
t

trevjones

08/14/2018, 3:25 AM
I think the task type ProcessResources is a task that operates on src/*/resources items. but you are trying to process an android resource. can you use
${applicationId}
in any xml res file or does that only work in the manifest?
m

max

08/14/2018, 6:11 PM
Thank you @trevjones I don’t know how didn’t i came across this stackoverflow answer, I’ll try this now. It should work. I think I was just stuck on looking into that ProcessResources as a solution. Out of pure curiosity then: about the task configuration I posted in the beginning, if I want to process and expand some other Android specific templates (in
src/res
not in
src/resources
) will this task be useful at all? I can probably use
from
method of this task for this?
t

trevjones

08/14/2018, 6:13 PM
that part gets complicated because of the timing of when that android tool chain handles resource processing. It would probably be more appropriate to implement a custom transform. http://google.github.io/android-gradle-dsl/javadoc/current/
👍 1