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.
Create an android application by clicking on new in the eclipse file explorer and choose android application. provide the name of your application which is going to display after the installtion of the application on android device. then write the project name which is going to shown under the project explorer of your eclipse. he provide the name of your package or use default name com.example.helloworld. Click next and take you to the next dialog where its tells you that what is going to create and click next , next and next and choose blank activity. your project is created now.
Create an android application by clicking on new in the eclipse file explorer and choose android application. provide the name of your application which is going to display after the installtion of the application on android device. then write the project name which is going to shown under the project explorer of your eclipse. he provide the name of your package or use default name com.example.helloworld. Click next and take you to the next dialog where its tells you that what is going to create and click next , next and next and choose blank activity. your project is created now.
Open
the source folder.Open the org.example.hello Android 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 AVD for Nexus 4, and I described
how to create it in a previous movie. I'll
click the Run button on
the toolbar. If
this is the first time you've run this app, you might see
this Run As dialogue, but if you've run it previously, you wont. 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 app's activities. This
is the base package and this package is the globally unique ID for your app. The
package is registered in the AndroidManifest 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 R. It
has nested classes and fields representing resources
that are bundled with the application. A
new project would, for example, have a field named drawable.iclauncher. 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 see a version of the graphic in the XHDPI folder, but you might
see versions in the XXHDPI, MDPI, and HDPI. This
Java ID 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 run time. When
you develop in Eclipse, you're automatically running a server that's running
in the background and watching the res directory and its sub directories.
Whenever you add or change a resource, such as
this graphic, or
an XML file, the R 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 I'll 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, android-support-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 res directory, which has directories and files that map
to classes and fields, in the generated R 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 directory. It's
managed for you. It'll
include compiled files. Including
.apk files that contain your compiled class files from your own Java code,
jar files for libraries your app uses, 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 to 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 just 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 partylibraries, this directory is a great
place to put them. When
you copy a library to this directory inEclipse, it isn't added to the projects
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 files that define your app's 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 contain XML files. Layout
has files that control the layout of your app's screens.
Menu has files that
declare menu and action bar items. And
values has files for strings, dimensions, and styles. We'll
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 has 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 let 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 app's identity, control how it appears on
an Android device's start screen, and
declare its activities and other capabilities. A
lot of an Android app's 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 subfolders of res always look 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.


0 comments:
Post a Comment