The question
When you need to use resource files, such as images, in your Android project, typically you put them in the res
directory (e.g. res/drawable
), and the Android build process picks them up by default. But what if your resource files come from a directory outside of your Android project? How do you copy them into a folder like res/drawable
during sync or build?
What I have tried
I have a feeling that the solution is to write Gradle code, but I'm not sure how to do it. I tried the following code in my app
module build.gradle
file:
task copyResources(type: Copy) {
from '../../../images'
into 'res/drawable'
}
But it did not copy anything as far as I can tell. This is probably just my ignorance of how to use Gradle, and I could use some help.
I realize I could manually copy from ../../../images
to res/drawable
, but let's say those files change often, and I want to get the current version automatically whenever I sync or maybe whenever I build. If this is possible, I would appreciate knowing how to do it. If it is not possible, I would like to know that as well.