The basic thing which every Android developer must know is the Android File Structure, to understand the basics of android development, In this tutorial you will learn the basics of file structure.
An Android project is designed to help you develop a single Android app and it has a specific structure with a set of Directory and file names that are always the same.
I’ll describe these using the hello world application that I built in previous tutorial, How to Create New Projects. If you don’t already have that application open you can import a version of it from the exercise file.
Now select File, import then in the import dialog under general I’ll choose existing projects into work space and click Next.
Now to select archive file and browse and then I’ll locate the hello android zip file which you have download from the above button.
Follow the rest of the prompts to import the project, when the project is imported into the package Explorer view double-click to open it up, then open the one Java class that was generated.
When the project was created open the source Folder opened the org.example.helloandroid package and open mainactivity.java
Then run the app I’m going to use an emulator, which I’ve already started up it’s named a VD for nexus 4 and I described how to create it in a previous tutorial, How to Create New Projects. Now click the Run button on the toolbar, if this is the first time you’ve run this app you might see this run as dialog but if you’ve run it previously you won’t I’ll choose android application and click OK.
Then i’ll switch over to the emulator and wait for a moment and the application opens, so now I’ll go back to eclipse and talk through the directory structure of an android project.
The first folder is the source folder spelled SRC this contains your Java code there’s a package that contains classes representing your apps activity.
This is the base package and this package is the global unique ID for your app the package is registered in the Android manifest file which I’ll describe in detail later it’s in the root elements package attribute and again the package must be universally unique because it’s used by the operating system to uniquely identify the app.
Next is the gen folder this contains classes that are generated automatically during development one of the most important is simply named our it has nested classes and fields representing resources that are bundled with the application.
New project would for example have a field named draggle IC launcher and that’s an addressable Java ID that points to a resource in the res folder anything within the drawable class is placed in one of these drawable folders and if it’s a drawable it’s a graphic. You should always be a version of the graphic in the xhdpi folder but you might see versions in the xxhdpi, mdpi and hdpi.
This Java IDE points to one of these files and which one is selected depends on the pixel density of the device it’s selected by the operating system at runtime when you develop an eclipse you’re automatically running a server that’s running in the background and watching the re s directory and its subdirectories whenever you add or change a resource such as this graphic or an XML file the our class is automatically regenerated don’t change this class yourself it should only be modified by the development tools.
Next is the SDK folder this points to a jar file that’s a part of your SDK installation I’ll expand this to show the exact location and notice that it’s under android 19 the api version that matches up with android 4.4 or kitkat.
You can change this by changing the target SDK you do this through the project preferences I’ll click on the project then go to project properties then I’ll go to Android and show that the project build target is set to android 4.4 or API level 19 if I were to change this and click OK and then clean the project by choosing project clean and clicking ok after a few moments.
You will see that the version of Android that’s indicated here is Android 4.3 or jelly bean I’ll switch it back again by once again changing the project properties and going back to KitKat.
The Android private libraries include one reference androids apart v4 jar this is called the Android support library and it contains packages and classes that let you emulate modern features of Android apps on older versions of the Android operating system notice that this is a complete copy of the jar file it’s not a reference to something in the SDK folder and that’s because when you create a new project in this version of the developer tools this support library is copied over automatically.
Next is the assets folder which is empty by default the assets folder can contain any files you want to include in your project that don’t have to be directly addressable as Java objects unlike the RTS directory which has directories and files that map to classes and fields in the generated our class these files are just packaged with the app you can add anything here that your app needs.
The bin directory is like the gen director it’s managed for you it will include compiled files including .apk files that contain your compiled class files from your own Java code jar files for libraries your app users and other critical resources like the contents of the gen directory you won’t change the contents of this directory directly but if you see anything in the bin directory that looks suspicious you can clean the project empty it and rebuild it from scratch.
The libs directory is a good place to add Java libraries as I described a new project comes with one library jar already in place the support library your app might not need this library but many do so it’s added for you and if you need to add any other third-party libraries this directory is a great place to put them when you copy a library to this directory in Eclipse it isn’t added to the project’s class-path automatically you have to do that yourself but it’s just like working in any Java environment.
The res directory as I previously described contains a variety of file to define your apps appearance and behavior graphic files are placed in the drawable directories I’ll show you later in the course how to create multiple versions of a graphic file for different screens these directories are named to indicate which screen their contents are for the layout, menu and values directories contained XML files. Layout has filed to control the layout of your app screens, menu has files that declare menu and action bar items and values has files for Springs dimensions and styles will get to each of these file types later in the course and you can also create other resource types that aren’t represented in a brand new Android project including anim for animation resources and color for predefined colors.
Finally there’s the all-important manifest file this is an XML file which always have the same name androidmanifest.xml when you open this file in Eclipse the first time you’ll see this graphical UI that lets you make a lot of changes there are multiple tabs down here that lets you get to all the various options but this is just an XML file and once you get to know its structure you might choose to modify it directly.
This is where you’ll set your apps identity control how it appears on an Android devices start screen and declare its activities and other capabilities. A lot of an Android apps behavior is managed here rather than in java code, we’ll get into the details of this manifest file very early in the course so that’s a look at the basic structure of an Android project again.
The folder names are always the same but the Java packages will differ depending on your app the Android manifest file always has the same name and the sub folders of res always looked the same to be effective as an Android developer you should get to know this directory structure and understand how the operating system puts it to use.
Subscribe the channel to get latest updates on tutorials, and keep visiting the blog for latest tutorials.
The post Android SDK Essential Training – Android File Structure Guide appeared first on Junaid Shahid | P-Blogger.