01 04 - android set up and creating an android project
-
Upload
siva-reddy -
Category
Technology
-
view
237 -
download
1
description
Transcript of 01 04 - android set up and creating an android project
![Page 1: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/1.jpg)
Android Application DevelopmentEnvironment Setup
![Page 2: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/2.jpg)
System Requirements
Setting up Development Environment
Supported OS1. Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7
(32- or 64-bit)2. Mac OS X 10.5.8 or later (x86 only)3. Linux (tested on Ubuntu Linux, Lucid Lynx)
Supported Development Environment (Eclipse IDE based)1. Eclipse 3.4 (Ganymede) or greater/Eclipse Classic (versions
3.5.1 and higher)2. JDK 1.5 or 1.63. ADT Plugin
![Page 3: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/3.jpg)
To set up the development environment, we need:
1. Java Development Kit (JDK 1.5+, 1.6 is preferable)
2. Eclipse IDE
3. Android SDK
Setting up Development Environment(Contd.)
![Page 4: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/4.jpg)
JDK for Java SE 6
• Overview
• Java 6 is newest, best, and especially fastest version
– Java 5 supported by Android but not recommended
• For PC, Linux, Solaris, follow directions at
• http://www.oracle.com/technetwork/java/javase/downloads/
– Get JDK, not just JRE
– Get SE (Standard Edition), not EE or Micro Edition
– Don’t get version with the NetBeans IDE
• For MacOS, Java is preinstalled & updated automatically
![Page 5: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/5.jpg)
Installing Java SE 6
• Install Java 6• http://www.oracle.com/technetwork/java/javase/downloads/
![Page 6: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/6.jpg)
Setting up Development Environment (Contd.)
First we install JDK
We have already done that
![Page 7: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/7.jpg)
The Android SDK• Overview
– Android-specific libraries
– Dalvik (Android virtual machine) compiler
– Android emulator (to run without physical device)
– DDMS debugging environment
• • Documentation– Installation
• http://developer.android.com/sdk/installing.html
– – Developer’s Guide
• Developer s • http://developer.android.com/guide/developing/index.html
– – JavaDoc (API Reference)
• http://developer.android.com/reference/classes.html
– – Tutorials and articles
• http://developer.android.com/resources/index.html 12
![Page 8: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/8.jpg)
Android SDK
Setting up Development Environment (Contd.)
Link: http://developer.android.com/sdk/index.html
Download and Install the SDK starter package from the table above (Highlighted)
![Page 9: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/9.jpg)
Android Environment: Eclipse & ADT
Android SDKEclipse
ADT
Android …..
……………….
Android 3.2
Android 4.x
Android 2.2
Google API 2.2
SDK Manager
AVD Manager
Manages
Emulator
![Page 10: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/10.jpg)
Installing Eclipse
• Go to eclipse.org, click on “Downloads”
• – Results in
• http://eclipse.org/downloads/
• – Can use either “for Java” or
• “for Java EE”.
• I use EE version since I also use Eclipse for Web apps.
• Latest version (3.6 – Helios) recommended.
• Previous version (3.5 – Ganymede) still supported
• Older versions (3.4 and earlier) not supported
![Page 11: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/11.jpg)
Running Eclipse• Unzip the downloaded file (no installer!)
– Call the folder you unzip into “installDir”
• Double click eclipse.exe– From installDir/bin
• Click on• “Workbench” icon
– Next time you bring up Eclipse, it will come up in workbench automatically
• Shortcut– Many developers put Eclipse link on their desktop
• R-click eclipse.exe, Copy, then go to desktop, R-click, and Paste Shortcut (not just Paste!)
![Page 12: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/12.jpg)
Setting up Development Environment (Contd.)
![Page 13: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/13.jpg)
Setting up Development Environment (Contd.)
We’ll setup Eclipse IndigoStand-alone Eclipse: just decompress and run eclipse.exe
You can create a shortcut in the desktop for eclipse.exe
![Page 14: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/14.jpg)
Eclipse
• Overview– Eclipse is a free open source IDE (Integrated– Development Environment). Support for Java, HTML,– CSS, JavaScript, C++, PHP, and more.– Google has free Eclipse plugin to integrate with the Android SDK.
• Features– General
• Checks your syntax as you type• Automatically compiles every time you save file• Refactoring, debugging, templates for common tasks, etc.
– Android-specific• Deploy apps to Android emulator• Configure virtual environments• Drag-and-drop GUI builder
![Page 15: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/15.jpg)
Setting up Development Environment (Contd.)
We’ll setup Eclipse Indigo
Choose your WorkSpace
![Page 16: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/16.jpg)
Setting up Development Environment (Contd.)
We’ll setup Eclipse Indigo
![Page 17: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/17.jpg)
Setting up Development Environment (Contd.)
We’ll setup Eclipse Indigo
We’ll become familiar to our new IDE gradually and I swear you’ll start loving it
![Page 18: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/18.jpg)
Setting up Development Environment (Contd.)
We’ll setup ADT Plugin
![Page 19: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/19.jpg)
Setting up Development Environment (Contd.)We’ll setup ADT Plug-in
![Page 20: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/20.jpg)
Setting up Development Environment (Contd.)
We’ll setup ADT Plugin
![Page 21: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/21.jpg)
Setting up Development Environment (Contd.)
We’ll setup ADT Plug-in
![Page 22: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/22.jpg)
Setting up Development Environment (Contd.)
We’ll setup ADT Plug-in
![Page 23: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/23.jpg)
Setting up Development Environment (Contd.)
We’ll setup ADT Plug-in
![Page 24: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/24.jpg)
Setting up Development Environment (Contd.)
We’ll setup ADT Plug-in
Adding ADT Pluging is DONE… You’ll now get a message
![Page 25: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/25.jpg)
Setting up Development Environment (Contd.)
We’ll setup android SDK
After restarting Eclipse we get:
Don’t forget to ask me about the red marks
![Page 26: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/26.jpg)
Setting up Development Environment (Contd.)
We’ll setup android SDK
SDK and AVD Manager: If we click on it:
So, we have to set the location of Android SDK and show it to our IDE
To do so….
![Page 27: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/27.jpg)
Setting up Development Environment (Contd.)
We’ll setup android SDK
![Page 28: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/28.jpg)
Setting up Development Environment (Contd.)
We’ll setup android SDK
![Page 29: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/29.jpg)
Setting up Development Environment (Contd.)
We’ll setup android SDK
![Page 30: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/30.jpg)
Setting up Development Environment (Contd.)
We’ll setup android SDK
![Page 31: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/31.jpg)
Setting up Development Environment (Contd.)
We’ll setup DDMS
Now We are Ready
![Page 32: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/32.jpg)
Let’s say “Hello” to the Android World!
![Page 33: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/33.jpg)
Let’s Go Deep…
Created Project has the following structure
Project Structure
-Source (src)-Generated Class (gen)-Android 1.6 library-Assets (assets)-Resource(res)
-drawable-hdpi-drawable-ldpi-drawable-mdpi-layout-values
-AndroidMenifest.xml-default.properties
![Page 34: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/34.jpg)
Let’s Go Deep… (Contd.)
To run the app in emulator, we have to do the following steps:
1. Create AVD (Android Virtual Device)2. Create Run Configuration3. Run the Application
To run the app in device, we have to do the following steps:
1. Install device driver2. Connect device through USB3. Create Run Configuration4. Run the Application
We’ll run the app in emulator for now
![Page 35: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/35.jpg)
Let’s Go Deep… (Contd.)
1. Create AVD (Android Virtual Device)
Use Android SDK & AVD Manager to create AVD
![Page 36: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/36.jpg)
Let’s Go Deep… (Contd.)
2. Create Run Configuration
1. Create a Run Configuration
2. Browse and selectthe project to run
![Page 37: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/37.jpg)
Let’s Go Deep… (Contd.)
3. Select AVD & Run
Click Run to start AVD/emulator
![Page 38: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/38.jpg)
Let’s Go Deep… (Contd.)
Result in Emulator
Now its time to analyze how it works
![Page 39: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/39.jpg)
Create a new Project in Eclipse
To create a new project:1.Start Eclipse2.Select File> New> Project.3.Select Android> Android Project, and click Next.
Select Android Project, a new window will open.
Specify the Project Name (Ex : HelloWorld).
![Page 40: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/40.jpg)
Create a new Project in Eclipse (Cont)
On The same window select the build target and specify the Application Name, Package Name, Activity Name and the Minimum SDK version.
Click on Finish. The new Android Project will be opened.
![Page 41: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/41.jpg)
Create a new Project in Eclipse (Cont)
Once you complete the New Project Wizard, ADT creates the following folders and files in your new project:
src/ - Includes your stub Activity Java file. All other Java files for your application go here. <Android Version>/ - (e.g., Android 1.5/) Includes the android.jar file that your application will build against. Gen/ - This contains the Java files generated by ADT, such as your R.java file and interfaces created from AIDL files. assets/ - This is empty. You can use it to store raw asset files.bin/ - stores the compiled application
bin/classes/ - stores the compiled Java classes bin/classes.dex - stores the executable created from compiled Java classes bin/app.apk – holds the Android application.
res/ - A folder for your application resources, such as drawable files, layout files, string values, etc.
res/ - resources used in the application res/drawable/ - for images res/layout/ - for XML-based UI layout res/raw/ - for general-purpose files res/values/ - for strings, dimensionsres/xml/ - for general-purpose XML files
AndroidManifest.xml - The Android Manifest for your project. default.properties - This file contains project settings, such as the build target.
![Page 42: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/42.jpg)
Create a new Project in Eclipse (Cont)
The new created project will have the following main entities.
• HelloAndroid.java- The default main Activity created while creating the project. It would contain all the logic that needs to be implemented for the main page.
• Main.xml- This xml file will comprise of the view part i.e. how the main Activity will look like.
• AndroidManifest.xml- This is the main configuration file that will contain all the information about the application like the details of all the activities, the main activity, the permissions for the application etc.
• Strings.xml- This file contains the string definitions that we use in our android application.
• There is one more file R.java in the application. This is the most important file as it contains the list of compiled objects representation of the layout defined in the layout files.
• R.java is generated automatically at the compile time if there are no compilation errors and cannot be modified by the user.
![Page 43: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/43.jpg)
Create a new Project in Eclipse (Cont)
![Page 44: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/44.jpg)
Compilation process
![Page 45: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/45.jpg)
Project Structure…
Created Project has the following structure
Project Structure
-Source (src)-Generated Class (gen)-Android 1.6 library-Assets (assets)-Resource(res)
-drawable-hdpi-drawable-ldpi-drawable-mdpi-layout-values
-AndroidMenifest.xml-default.properties
![Page 46: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/46.jpg)
Project Structure (Contd.)
-Source (src)
We have used only one class here which is an Activity named HalloActivity. We’ll describe about Activity in detail with lifecycle shortly. For now we can consider Activity as Android analogue for the window or dialog in a desktop application. It can load view from xml layout (here main.xml under res/layout folder)
In the HelloActivity class the view of the Activity is set from main.xml given below
![Page 47: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/47.jpg)
Project Structure (Contd.)
-res/layout/main.xml
1. UI Layout can be defined from source code using View or by layout xmls. 2. The layout xml can be generated by visual tool given by ADT
![Page 48: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/48.jpg)
Project Structure (Contd.)-res/drawable
1. From Android 1.6 to support different screen sizes and screen densities graphic files are kept in 3 different folders drawable-hdpi, drawable-ldpi and drawable-mdpi
2. In our current project, they contain only default icon file with different dimensions to support devices with different screen resolution.
-assets
Holds other static files you wish packaged with the application for deployment onto the device. In this project, we have none
-gen/R.java -values/strings.xml
![Page 49: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/49.jpg)
Project Structure (Contd.)-AndroidMenifest.xml
XML file describing the application being built and what components – activities, services, etc. – are being supplied by that application
![Page 50: 01 04 - android set up and creating an android project](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f7686b4c9052a518b477e/html5/thumbnails/50.jpg)
Questions?