Reputation: 35997
I'm working on a project with a lot of .xml layout files. I want to organize them in separate folders.
It seems like Resource Merging would be the right solution.
http://tools.android.com/tech-docs/new-build-system/resource-merging
I want to split my layout folder in activity, listview, dialog, button, etc.
How do I modify my project and build.gradle file to accomplish this ?
Upvotes: 2
Views: 2237
Reputation: 80010
Resource merging isn't really the concept you're looking for here -- that document specifies how if you have multiple build types and flavors, how they combine to provide a single view of the project's resources that will be built into the final result. In your case, you probably have a single build type and flavor, and want to have subdirectories in your resources to help organize them better.
The bad news is that Android isn't very friendly about this. The build system expects resources to be arranged in a rigid format, with all layouts being in a single folder underneath your project root, for example, and it doesn't let you deviate from that. The best thing you can do is to have multiple resource folder trees, which would look like this:
AppModule
+ src
+ main
+ java
+ res
+ drawable
+ layout
+ ...etc...
+ extra-res
+ drawable
+ layout
+ ...etc...
Each resource sub-tree has its subdirectories in the same format. You don't need to have an exhaustive list of subdirectories in there if they're empty; just include the ones that have things you need.
To make this work, you need to have the following in your build.gradle script:
android {
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/extra-res']
}
}
}
Upvotes: 5