Customize your Android project structure to fit your needs
Android project structure is usually organized with a main folder containing a java folder and a res folder. The java folder contains all the Java classes file of your project. The res folder contains all resources of your Android project. So, it can make a lot of files with drawables, layouts, values, etc … When your work on a big project with a lot of screens and features, it can be problematic and make your life difficult.
With Android Studio and Gradle build system, an alternative solution can be applied. You can create multiple resources folder. For example, you can keep the classic res folder to store all the common resources in your project like colors or theme. And you can create a res folder for your screens. Then, put a folder by screen in that folder.
Imagine your app has 3 screens :
- Main
- Weather to display weather
- Cities to display weather for a list of cities
You could create the following structure :
- main/
- main/res
- main/res-screens
- main/res-screens/main
- main/res-screens/weather
- main/res-screens/cities
Inside Android Studio, the project structure is like that :
Finally, we need to declare to Android Studio to consider these new resources folder. To achieve that, you must open your build.gradle file and create a sourceSets section inside the android section :
sourceSets { main { res.srcDirs = [ 'src/main/res', 'src/main/res-screens/cities', 'src/main/res-screens/main', 'src/main/res-screen/weather' ] } }
With that great feature, you can now customize your Android project structure to fit your needs.
Leave a Reply
You must be logged in to post a comment.