Thursday, May 17, 2012

Android + NDK tips, part 2: Android project directory structure

An Android project folder is pretty cluttered. Most of the files and directory structure are determined by Eclipse and Android conventions, and many of the files and folders are auto-generated so there is nothing you can do about the clutter.

Below I describe the folder structure of an Android project. Please note that the terms "auto-generated" and "generated" are not the same. Auto-generated files are generated automatically on-demand, so you can safely delete them and they need not be checked-in to source control. Generated files are created by tools, but you can't delete them because they will not be regenerated. Auto-generated folders may contain content that is not auto-generated, so they are not always safe to delete.
Directory name   Purpose
--------------   -------
src              Conventional location for Android Java source code*
jni              Conventional location for C/C++ source code**
res              Conventional location for Android XML resource files
res/layout       Conventional location for dialog layouts
res/values       Conventional location for strings (to support internationalization)
res/drawable     Conventional location for bitmaps and other drawables
res/drawable-*   Auto-generated by Eclipse to hold different bitmaps for different screen densities
assets           Auto-generated by Eclipse for files to store in your *.apk (use AssetManager to read)
bin              Auto-generated by Eclipse to hold the *.apk, Java *.class files and other output files
gen              Auto-generated by Eclipse or vs-android to hold generated Java files
libs             Auto-generated by ndk-build to hold lib*.so file(s)
obj              Auto-generated by ndk-build to hold C/C++ object files
* Java package and class names are required to match the directory structure. A class named must be located at src/com/foo/
** However, C/C++ source code can be placed anywhere you want
File name               Purpose
---------               -------
.classpath              Unsure, may help find Java dependencies. Generated by Eclipse when making a project.
.project                Generated by Eclipse to hold the project's name.*
AndroidManifest.xml     Specifies App's icon, required Android version, and a list of all activities.      Unknown (generated)**      Unknown (generated)**
proguard.cfg            Unknown (generated). May be related to Java obfuscation***        Auto-generated to hold the location of the Android SDK on the current machine.
jni/          sub-makefile that describes the C++ static libraries and *.so files you want to build
jni/      contains settings that apply to all the C/C++ code 
                        (processor type, API level, standard library, project-wide compiler options)
build.xml               Unknown (required by vs-android only)
                        Note: in vs-android samples, the .* files are in the parent folder of 
                        everything else. But personally I have reconfigured my project so that these files 
                        are in the same folder as the files above.
(projname).vcxproj      vs-android project file
(projname).vcxproj.filters vs-android secondary project file****
(projname).sln          Visual studio solution file
(projname).suo          Auto-generated by Visual Studio for local user settings
(projname).vcxproj.user Auto-generated by Visual Studio for local user settings (one file is not enough?!)
(projname).sdf          Auto-generated by vs-android or VS. Probably a C++ symbol database (SQL Server Compact)
* .project is the Eclipse analogue of a Visual Studio project file, sort of, but it doesn't contain a list of the files that are in the project; in Eclipse, everything in the directory tree is implicitly part of the project. The project name is stored in the .project file, but as far as I can tell, this name is only cosmetic; it is not used in the output *.apk.
** or merely repeats the target SDK version from AndroidManifest.xml. A comment in the file claims the file is automatically generated, but apparently it is generated only once (on project creation). Eclipse will barf with a series of NullReferenceExceptions if the file is missing. For some reason there are two possible names for it; some projects use one name, others use the other name.
*** ProGuard is an obfuscation tool. I didn't ask for obfuscation, but Eclipse created proguard.cfg anyway.
**** *.vcxproj.filters specifies how files will be arranged into "Filters" (tree nodes that look like folders) in Visual Studio. I can't imagine why this information is not simply stored in the *.vcxproj file.


At 12/20/2013 6:59 PM, Anonymous Anonymous said...

excellent attempt to explain the file structure. Too bad there's no official description that I know of.

At 3/26/2017 11:29 PM, Blogger Geetha Devi said...

Very informative ..i suggest this blog to my friends..Thank you for sharing
Android Training in velachery | Android Training in chennai | Android Training in chennai with placement

At 3/26/2017 11:34 PM, Blogger Saranya N said...

Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
Android Training in chennai | Best Android Training in chennai|Android Training in chennai with placement | Android Training in velachery

At 6/26/2017 11:38 PM, Blogger Nandhini said...

Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.... Android Training in Bangalore

At 11/22/2017 4:33 AM, Blogger Raju said...

Real Estate Consultant in Chennai

At 6/28/2018 2:35 AM, Blogger Manoj said...

Excellent information with unique content and it is very useful to know about the information based on blogs.
me projects chennai | me project centers chennai.

At 7/04/2018 1:49 AM, Blogger Muthu Raj said...

It was a great blog. I would love to read more article from you.

Final Year Java Project Centres Chennai | Final Year Dotnet Project Centres Chennai.


Post a Comment

<< Home