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.
Add a resource directory. Click the target app module in the Project window, and then select File > New > Android resource directory. Fill in the details in the dialog: Directory name: The directory must be named in a way that's specific to the resource type and combination of configuration qualifiers.
Android Specify Alternative Resources 1 Create a new directory in res/ named in the form -. 2 Save the respective alternative resources in this new directory. The resource files must be named exactly the same as the default resource files. See More....
Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more. You should always externalize app resources such as images and strings from your code, so that you can maintain them independently.
The raw folder is created inside the res folder: main/res/raw. So we will simply create it inside the res folder. But before creating a raw folder let’s have a look at the asset folder in android which acts the same role as the raw folder in android studio. So let discuss how the resource raw folder is different from the assets folder?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With