Gary S. Gary S. - 11 months ago 38
Android Question

How to copy resources files from other directory into Android project during sync or build?

The question

When you need to use resource files, such as images, in your Android project, typically you put them in the
directory (e.g.
), 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
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

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
, 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.

Answer Source

See How to run copy task with android studio into assets folder

Can do with adding

preBuild.dependsOn copyResources

after task copyResources(){...} in your build.gradle.

But, it's not a good way for copying resources.