Configuring Your Project
In many of the samples in the book, we saw various settings in build.gradle
files:
- At the top level of the
Sampler
orSamplerJ
projects - In individual modules, such as
Bookmarker
The focus has been on where various settings reside in those files (e.g., stuff that goes in the dependencies
closure, stuff that goes in the android
closure).
However, Android Studio offers another way of manipulating those settings, via the Project Structure dialog. You can open this from the “File” > “Project Structure” main menu option, and it lets you manipulate many of the same things that we covered, but using a GUI rather than a text editor.
Risks and Rewards
So… why did we bother with all that build.gradle
stuff, if we could use a GUI?
Mostly, it is because not everything can be configured via the Project Structure dialog. You cannot enable data binding, for example. Nor can you add Gradle plugins, like the “safe args” plugin for the Navigation component. Once you get past some fairly basic settings, the Project Structure dialog cannot help you. So, understanding how build.gradle
files are set up is important, for those things that cannot be manipulated via the Project Structure dialog.
Also, if your build.gradle
file does contain things that cannot be managed by the Project Structure dialog, there is a risk that using the Project Structure dialog will somehow break those “things”. Bear in mind that a Gradle build file is a Groovy script — build.gradle
is a program that builds an object model with the details of how to build your app. While we have a lot of code generators, in Android and beyond, usually a code generator is a write-only tool. Using other data as input, the code generator writes out code. Here, though, the Project Structure dialog needs to modify code that is otherwise maintained by hand. That is a complex programming problem, and bugs in the Project Structure dialog might overwrite or otherwise mess up some of that hand-entered Groovy code.
Google obviously feels fairly confident in the Project Structure dialog, and you are welcome to use it. This chapter will outline what sorts of things you can configure using that dialog. Just remember that anything configurable in this dialog can be configured in by hand, typically in a build.gradle
file. And, be sure to keep good backups or version control history, to be able to recover if Project Structure breaks the build.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.