1

I'm an Android Studio noob. In 2.1.1, when I click on a file to edit, the file opens up in the edit pane and its tab usually reflects the name of the file. For instance, if I click on MyActivity.java, when it opens in the editor the tab for it says "MyActivity.java". This is useful because I often have many files open at the same time and I can quickly scan across them and see what they are.

But if I'm editing build.gradle the tab just says "app". Why?

Edit: if I open other gradle files, e.g., settings.gradle, the tab says "settings.gradle". XML files also seem to use their correct file name. So build.gradle seems to be special-cased. Why?

user316117
  • 7,971
  • 20
  • 83
  • 158
  • Because file named build.gradle is representing to the application structure so it's in simple is reference to complete app. – Harpreet May 23 '16 at 15:30
  • Thanks, but I'm afraid I don't understand/can't parse your answer. – user316117 May 23 '16 at 15:32
  • Try to understand this first http://stackoverflow.com/a/28981917/1164529 – Harpreet May 23 '16 at 15:38
  • In that linked question different answerers present many different, sometimes conflicting, perspectives on Gradle. But none of them addressed my question. – user316117 May 23 '16 at 15:59

1 Answers1

3

I'll abstract some details here, so I definitely recommend that you take a Gradle for Android course if you can. Udacity has one.

Essentially, Gradle creates a build.gradle file for the root folder of your project, for example, GooglePlayApp/. Then it creates a build.gradle file for every part of your project. By part, I mean the app itself, which is located in the app/ folder, any external Java libraries, located in their own folder(s), any external Android libraries, also located in their own folder(s), and so on.

Every one of these would have a build.gradle file. Gradle calls these parts, modules, in fact that's why under the Android view in the left pane in Android studio you see:

Build.gradle (module: project) // overall project build.gradle file
Build.gradle (module: app) // build.gradle file for your app
Build.gradle (module: myjavalibrary) // build.gradle file for a random java library
Build.gradle (module: myandroidlibrary) //build.gradle file for a random Android library

So to answer your question, Android Studio makes it easy for you to differentiate between these files by giving you the module name as opposed to the file name because the file name would be build.gradle for all of them. Let me know if I need to elaborate further in the comments.

Daniel
  • 2,355
  • 9
  • 23
  • 30
  • So the simple answer is that they can't call it "build.gradle" because there are multiple files with that name, so they call it "app" to avoid ambiguity. – user316117 May 23 '16 at 17:10
  • ... gosh, I sure hope I don't have to take a course in Gradle - I didn't have to take a course to use Eclipse. – user316117 May 23 '16 at 17:13
  • @user316117, ambiguity as to what build.gradle file you're working on, yes. Don't forget where the name "app" comes from though. It may not always be "app" if you change some defaults. – Daniel May 23 '16 at 17:49