Difference between build.gradle(Project) and build.gradle(Module)

后端 未结 3 1084
醉话见心
醉话见心 2020-11-28 22:41

I am trying to add a dependency of Android Asynchronous Http Client into my project. So there are two build.gradle files are there in the project.

3条回答
  •  时光取名叫无心
    2020-11-28 23:05

    It's a bit confusing because Android Studio by default shows both build.gradle files right next to each other (when using the Android view).

    If you switch to the Project view you can see the actual structure and where the different build.gradle files are located.

    The build.gradle (Project: MyApplication) file is in the root folder of the project and its configuration settings apply to every module in the project. A module is an isolated piece of the bigger project. In a multi-module project, these modules have their own jobs but work together to form the whole project. Most Android projects only have one module, the app module.

    The build.gradle (Module: app) file here is in the app folder. Its build settings apply only to the app module. If there were another module, then that module would have its own build.gradle file, too. As an example, I made a library project with three modules: a library module, a demo app module, and another app module that I plan to use for testing. Each of them have their own build.gradle files that I can tweak.

    In a basic project, almost everything you need to edit will be in the app module's build.gradle file. You can remember it like this:

    You're making an app, so go to the build.gradle (Module: app) file.

    Further reading

    • Configure Your Build (Android documentation--very readable and useful)
    • Introduction to multi-project builds (Gradle documentation)

提交回复
热议问题