Android Studio: Exclude resource file under resour

2019-01-07 21:20发布

问题:

I'm developing an android app using android studio as IDE.

My question is:
How to exclude certain files under certain directory during the process of building APK?

In my case, I want to exclude some images from building since the those files used in my project are designated to be downloaded from network in-app while during the development I hope to refer them in the layout.

After googling, I found some solutions:
Gradle 1.2: Exclude directory under resources sourceSets
How to exclude file from resources using Gradle and Android Studio?
And reference from gradle.org

Then I came up my solution in build.gradle:

sourceSets {
    main {
        resources.exclude '**/drawable/*'
        res.exclude '**/drawable/*'
    }
}

But it doesn't work, the image under res/drawable/ still shows up(before downloading).

The Android Studio version is currently 0.8.4.
Any idea would be appreciated.

回答1:

Exclude paths aren't currently supported for Android sourceSets. You can track this at bug https://code.google.com/p/android/issues/detail?id=64957

This is happening because Android sourceSets aren't the same as Java sourceSets; they're a custom implementation in the Android plugin, and don't automatically pick up all the features of their cousins. This will need to be specially implemented for Android, and it hasn't been done yet.