Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

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

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

Enter image description here

As per my understanding, there are different kind of dependencies:

  1. One which defined on the root level of build.gradle (Project:My-app)
  2. One inside the buildscript of the build.gradle (Project:My-app)
  3. Another is build.gradle (Modules:app)

This question is about repositories for dependencies of the buildScript, explain a bit about first two types.

Also build.gradle (Project:My-app) says

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

So I guess the dependency code of Android Asynchronous Http Client should be added in build.gradle (Module:app).

How does it all fit together?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

enter image description here

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

enter image description here

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.

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...