the mystery: android studio's project structure and build system
i don't know if this is because of the gradle build system (i'd wager it is), but i'll tell you what i've understood so far.
update 4: 2014/09/11 added cheat sheet for
variants(i finally feel confident to write this :d)
update 3: 2014/09/11 updated the comparison workspaces and projects to be precise
update 2: 2014/04/17 added more detail to as project structure
update 1: 2013/07/29 added intellij project structure
the intellij's project structure (shown at the end) is for intellij with the android plugin. the android studio, however, has a project structure divided like so:
structure: projects and modules
module in android studio is like a project in eclipse
project in android studio is like a workspace in eclipse (to be precise, a workspace with interdependent projects)
from the documentation (android studio is based on intellij idea) :
whatever you do in intellij idea, you do that in the context of a project. a project is an organizational unit that represents a complete software solution.
your finished product may be decomposed into a series of discrete, isolated modules, but it's a project definition that brings them together and ties them into a greater whole.
for android, it means one project per app, and one module per library and per test app.
there are multiple issues if you try to build multiple apps within the same project. it's possible, but if you try (like i did), you will see that almost everything is designed to work with a single app per project.
for example, there is an option to "rebuild the project", which makes no sense with multiple apps, many other project settings would be useless, and the built-in vcs system isn't great when you have multiple repositories.
structure: folder structure
top level folders
1. main project
this would be entire project context (eclipse land: like your workspace but limited to what's relevant to your project). ex:
helloworldproject if the name of the application you gave was
this where project specific metadata is stored by android studio (as). (eclipse land:
3. project module
this is the actual project. ex:
helloworld if your application name you gave was helloworld
this is where the gradle build system's jar wrapper i.e. this jar is how as communicates with gradle installed in windows (the os in my case).
5. external libraries
this is not actually a folder but a place where referenced libraries (eclipse land: referenced libraries) are shown. here's where the targeted platform is shown etc.
[side note: this where many of us in eclipse land used to delete the referenced libraries and fix project properties to fix reference errors, remember?]
project folder in detail
this is number #3 in the above list. has the following sub dirs
this has all the complete output of the
make process i.e. classes.dex, compiled classes and resources, etc.
in the android studio gui, only a few folders are shown. the important part is that your r.java is found here under
this is the standard libs folder that you see in eclipse land too
here, you only see the
res folder which correspond to the
src folder and
res folder in eclipse land. this is much welcomed simplification imho.
note on modules:
modules are like eclipse land projects. here the idea is that you have one application project (module #3 in the list above) and several library projects(as separate modules under the global project folder (#1 in the above list)) which the application project depends on. how these library projects can be re-used in other applications, i still haven't found out.
[side note: the whole re-organization has some benefits like simplifications in src folder, but so many complications. the complications are mainly due very very thin documentation on this new project layout.]
the new build system
explanation of flavors and buildtypes, etc - what is the hullabaloo about?
cheatsheet for flavors and buildtypes
buildtypes available by default on all projects. they are for building/compiling the same code to generate different apks. for example on
release apks you would want to run proguard(for obfuscation), sign it with your key (as against the debug key), run optimizations (maybe via proguard or other tools), use slightly different
packagenames (we use
debug), etc. we also use a debug flag (
buildconfig.debug) to turn off logging to logcat (since it makes the app slow) on
release builds. this makes for a faster
debug build during development but also an optimized
release build to put on play store.
product flavor: there are no default flavors available (or to be precise, the default flavor is blank/nameless).
flavors could be free version or paid version where they have different code. they share the same
main code but different versions(or no versions) of a few source code files or resources.
buildvariant is what a generated apk actually corresponds to. they are named like so (in order)
product flavor +
build type =
example 1: if you have
paid as two flavors. the build variants you would get are:
free - debug
free - release
paid - debug
paid - release
so that is 4 possible apk configurations. a few configurations may not make sense in a particular project, but they are available.
example 2: (for new projects/ no flavors) you have 2
buildvariants or apks available, since the default flavor is nameless/blank:
compare this with intellij's project structure if that helps:
the .idea (1) folder contains a number of subfolders, mainly with internal intellij idea information.
the src (2) folder contains the myactivity.java (3) file source code that implements the functionality of your application. the file belongs to the com.example package.
the res (4) folder contains various visual resources.
the layout/main.xml file (5) defines the appearance of the application constituted of resources of various types.
the values folder (6) is intended for storing .xml files that describe resources of various types. presently, the folder contains a strings.xml file with string resources definitions. as you will see from the adding a color section, the layout folder can also contain, for example, a descriptor of colors.
the drawable folder (7) contains images.
the gen (8) folder contains the r.java (9) file that links the visual resources and the java source code. as you will see from the sections below, intellij idea supports tight integration between static resources and r.java. as soon as any resources are added or removed, the corresponding classes and class fields in r.java are automatically generated or removed accordingly. the r.java file also belongs to the com.example package.
for android studio 3.0.1 and selected all features:
- android o latest
- android auto
- android things
- android wear
- android tv
- c++ support
- kotlin support
the structure in version 3.0.1 does not look at all like all other answers.
recent structure is as displayed in 2018, android studio 3.0.1 01/2018.
newbie kinda found something resembling to usable in feature sub-folder:
update your android studio 3.0.1 01_2018:
google discontinue the support for the android developer tools (adt) in eclipse is ending, per our announcement. you should migrate your app development projects to android studio as soon as possible. for more information on transitioning to android studio, see migrating to android studio.
android studio: app\build\source\r\debug\com.example.app\r.java
why are these paths different? why is my r.java located in a debug folder in android studio? this lead to some errors early on, and if anyone has any insight into these differences i would appreciate them.
simply put, android studio is configured to build a debug build type on your system.
eclipse/adt is designed to support a single build at a time (from what i can tell). one of the primary goals of the new build system (from the user guide):
make it easy to create several variants of an application,
either for multi-apk distribution or for different flavors of an application
so where as eclipse/adt could generate one
r.java file, android studio supports multiple. the generated
r.java is located in the
debug folder because by default the new build system supports
release build types off the bat. if you changed your build variant (button, lower left hand corner of as) to release as will generate
r.java in the
this might not mean anything for simple projects, but the support of build variants means a drastic simplification of the build process for many developers, including the project i'm working on.
our project supports 4 flavors with 2 build types (debug and release), to support a total of 8 different apk combinations. and each of those combinations have slightly different configurations, so this build system really worked out for us. my android studio is installed on a different machine, but if memory serves my correctly the
r.java file exists in
build/source/<flavor>/r/<build type>/package/r.java. when our ci server builds the apk files it uses each of these
r.java files to generate separate packages.
- Android Studio Project Structure (v.s. Eclipse Project Structure)
- How to import Eclipse project with source control to Android Studio without changing the directory structure to the Gradle one?
- Android Eclipse to Android Studio ---> Project Structure
- How do you import an Eclipse project into Android Studio now?
- How to import eclipse library project from github to android studio project?
- Android Test Project Directory Structure When Using Eclipse
- How to import android studio project in eclipse which use library?
- Android Studio fails to import my Eclipse Projects, either directly or as Gradle project
- Importing an app-compat v7 library eclipse project to android studio
- Android Studio 0.4.3 Eclipse project without gradle
- Error on importing an Eclipse project into Android Studio
- Import Eclipse project to Android studio project
- Android Studio import Eclipse project
- Convert Eclipse Workspace to Android Studio Project
- "Gradle location is incorrect" when migrating android project from eclipse to android studio
- Best git structure for importing android dependent project with egit in eclipse
- Importing Eclipse project with 2 libraries to Android Studio
- Eclipse project stored in SVN checkout in Android studio
- Cannot import Eclipse project into Android Studio
- Using Android Studio to work on an Eclipse project
- properties file not found after migrating Android project from eclipse to Android Studio
- One Android project for Eclipse and Android Studio
- Importing project from eclipse to android studio (unresolved resources)
- Errors when importing a project from Eclipse to Android Studio
- Problems importing an Eclipse project into Android Studio
- How do I import an existing android studio project to eclipse so that it is native and becomes a codename application?
- Import Old Eclipse Project Into Android Studio
- no gradle file in eclipse project Android studio
- Migrating eclipse project to android studio shows install error
- Importing project from Eclipse to Android Studio - Dependencies
More Query from same tag
- Finding source line on exception (Android, Eclipse)
- Jersey Rest service: 'Resource /Servers is not open'
- Include Gradle dependencies in the classpath of a debug launch of another project in Eclipse
- I get an error while trying to run a class about a main method not being found in the class
- Repeated instances of game draw dialog box
- What is 'required from here' error
- Newlines and blank lines formatting in eclipse
- eclipse cannot find main method from given launch configuration
- How to import an existing Android Library project into Eclipse workspace
- How to build eclipse project files for android project
- Facing issue after importing project into eclipse
- XText in a RCP product
- Can't get last value from JSON
- Eclipse complains android:scrollbars and android:fadingEdge do not allow Strings - includes code
- Is it possible to create a non modal non-cancellable job in eclipse?
- I am using eclipse and it stops responding when I open an android layout file
- Property file always fails to load immediately when I create a new android application project
- How to add the "provider" info for an eclipse plugin
- Android Application NFC errors in eclipse with android SDK
- Is it possible to interrupt and cancel a build when a file is saved or key typed?
- Download and install JavaFX for Eclipse
- How do I toggle the menu button icon and tooltip text for an Eclipse plugin?
- Eclipse (java) - Cannot be resolved to a type
- How can I use Twitter4J in open source without exposing my oauth secret tokens?
- How do you point an eclipse project to a specific AVD?
- Eclipse - Font changed after updating to Windows 10
- Eclipse Eclipse is running under 1.6, but 1.7 is needed
- DateFormat works in native JUnit test, but not executed by Gradle
- Eclipse BPMN2 Modeller - linking from one BPMN file to another?
- Maven Build issues: Cannot access nexus in offline mode and the artifact is not downloaded