It becomes difficult to maintain and manage resources as the project grows.
How can we manage resources?
We can easily manage resources like java and Kotlin files. We can group our resources for adding new features or modules. By default, your resources are located in module-name/src/source-set-name/res/.
For example, resources for your module’s main source set are in src/main/res/ and resources for the debug source set are in src/debug/res/. However, you can change these paths to any other location (relative to the build.gradle file) with the res.srcDirs property in the sourceSets {} block.
Let’s suppose we want to add new features in a core project but don’t want to mess with the core.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
sourceSets { // Encapsulates configurations for the main source set. main { // Changes the directory for Java sources. The default directory is // 'src/main/java'. java.srcDirs += 'src/main/kotlin' // If you list multiple directories, Gradle uses all of them to collect // sources. Because Gradle gives these directories equal priority, if // you define the same resource in more than one directory, you get an // error when merging resources. The default directory is 'src/main/res'. res.srcDirs = ['src/main/helpdesk', 'src/main/res'] } } |
I hope this blog is useful to you. Thanks for reading.