-2

Android Studio generates a very deep directory structure for a new app. An example app from Google shows the actual Java code at: MyFirstApp/app/src/test/java/com/hfad/myfirstapp/ExampleUnitTest.java

In other frameworks I've used I've seen the IDE generate a directory structure that's a few folders wide with lots of files. What is the benefit of Android's deep and empty directory structure? Do I have to use it or can I just trim it down to something like /myapp/src/main.java?

Scott B
  • 1
  • 5

2 Answers2

0

Well, there are a lot of parts here, and it is mostly just for organization.

MyFirstApp/app/src/test/java/com/hfad/myfirstapp/ExampleUnitTest.java

  • MyFirstApp - the name of the project
  • app - the actual build within - could also be wear for the android wear build
  • src - the main javasource directory
  • test - these should only be compiled when testing, and not exported with the apk main will be the code th build the APK
  • java - actual javasource, may also be resources for optional extras
  • com/hfad/myfirstapp - the package identifier, you will see that Google follows com.google.<appname>
  • ExampleUnitTest.java - the actual name of the class

For mostly any java project this is the generally agreed upon structure - with the exception of an extra level here to seperate app / wear - which is specific to Android.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123
0

Android default gradle template project has main project (with top level build.gradle) and module project app(with specific app build.gradle) so you have "app". https://stackoverflow.com/a/23241888/289686

There is maven directory structure, which gradle uses, so you have "src/main/java" https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

Android application id (also package name earlier) is used to identify app on google play, so you have "com/hfad/myfirstapp" http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename

Community
  • 1
  • 1
logcat
  • 3,435
  • 1
  • 29
  • 44