Programming with Android:
SDK install and initial setup
Luca Bedogni
Marco Di Felice
Dipartimento di Informatica: Scienza e Ingegneria
Università di Bologna
SDK and initial setup: Outline
Ø Today:
§  How to setup a machine to start developing Android
applications
§  An overview of an Android project
§  Some useful tools
§  Your first Android application
•  Maybe on a real device!
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
2
Two options
Ø Historically Android development was in Eclipse
Ø Download the SDK
Ø Install the Android plugin
Ø Now there is Android Studio
Ø You still have to download the SDK
Ø Customized environment
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
3
Which one?
Ø For the class, it’s the same
Ø If you already use and love Eclipse, go with it
Ø You might see examples done in both platforms
Ø You can always import an Eclipse project into Android
Studio
Ø The inverse is difficult
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
4
Android Studio
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
5
Where and how to get it
Ø Go to
http://developer.android.com/sdk/installing/studio.html
Ø Download Android Studio
and the SDK
Ø Install it and you’re done!
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
6
Basic requirements
Ø How to develop Android applications?
Ø Linux/Mac OS X/Windows? Doesn’t matter
Ø A real device is not mandatory
Ø Code your application in the IDE
Ø Test it with the emulator
Ø Deploy it on a real device
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
7
SDK tools
Ø  Android tool
Ø  Used to get APIs
and add-ons
Ø  You can also start it
from Android Studio
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
8
Your first Android application
Ø Go to File > New Project
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
9
Testing on the emulator
Ø Select “Launch Emulator”
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
10
Creating an emulator
Ø Can configure several
options
Ø You can create as many
as you want
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
11
Did everything went fine?
Ø Test in on the emulator
Ø You should see something
similar to this
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
12
Hello world, Android!
Ø Anatomy of an application
Ø Activity: what is started
Ø View: what is seen
Ø Intent: how to communicate with others
Ø Mix of XML and Java
Ø Generally XML for layouts
Ø Java for the app logic
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
13
Application structure
Ø Even the simplest application
has a lot of files
Ø Some are autogenerated
Ø Each project contains
Ø Activities
Ø Layouts
Ø XML files
Ø AndroidManifest.xml
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
14
build
Ø Autogenerated files
Ø No need to modify them
Ø Some are autogenerated
Ø Each project contains
Ø Activities
Ø Layouts
Ø XML files
Ø AndroidManifest.xml
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
15
src
Ø All the code of your application
Ø The java folder contains… the
java code!
Ø Inside res there are a lot of
resources
Ø Images
Ø Layouts
Ø Xml files
Ø AndroidManifest.xml
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
16
AndroidManifest.xml
Ø Mandatory file for every
application
Ø Contains:
Ø Application declaration
Ø Permissions
Ø Intent filters
Ø Targets
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
17
How to test
Ø Via an AVD
Ø Fast, possible to have different resolutions, APIs
Ø Not a real device
Ø On a real device
Ø You get exactly what is deployed
Ø Must own a real device
Ø So?
Ø Test in on AVDs.
Ø When you feel that the application is ready, go with a real device
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
18
How to deploy
Ø Android applications must be signed before installing
them on a real device
Ø 
Ø 
Ø 
Luca Bedogni, Marco Di Felice
-
You need a key for this
and you can generate one
from the menu.
Programming with Android – SDK install and initial setup
19
Eclipse
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
20
SDK and initial setup: 3 step setup
Ø Download Android SDK for your platform:
http://developer.android.com/sdk/index.html
Ø Execute (and then select the Android API version):
android-sdk-xxx/tools/android
Ø Install the ADT plugin for Eclipse:
http://www.eclipse.org/downloads/
https://dl-ssl.google.com/android/eclipse
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
21
Inside the SDK
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
22
ADT plugin for Eclipse
v Useful to run applications via Eclipse, highly
reccomended
v Go to
http://developer.android.com/sdk/eclipse-adt.html
v Pick the repository (actually
https://dl-ssl.google.com/android/eclipse/)
v Add a repository in Eclipse and download the
“Developers Tools”
v This will make a virtual bridge between eclipse and
the SDK
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
Create a Project
v Create it under Eclipse
§  Assign an SDK target
§  Choose an application name
§  Choose a package name
§  Create an activity and assign a name
v Run it to test that everything is ok
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
24
Create an AVD
v AVD means Android Virtual Device
v Test the application before running it
on a device
v Multiple APIs → Multiple targets
v Makes it faster (and cheap) to test
application on different
configurations/resolutions/storage
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
25
Project contents
v Project name
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
26
Project contents
v Project name
v Src folder with java files
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
27
Project contents
v Project name
v Src folder with java files
v Auto-generated files
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
28
Project contents
v Project name
v Src folder with java files
v Auto-generated files
v Android's base files
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
29
Project contents
v Project name
v Src folder with java files
v Auto-generated files
v Android's base files
v Compiled files
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
30
Project contents
v Project name
v Src folder with java files
v Auto-generated files
v Android's base files
v Compiled files
v Resources files
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
31
Project contents
v Project name
v Src folder with java files
v Auto-generated files
v Android's base files
v Compiled files
v Resources files
v Android Manifest
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
32
How to deploy
v Android applications must be signed before they can
be installed on a device
v Eclipse can sign applications
§  Debug mode, just to test it on your device
§  Release mode, when it's ready for other users
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
33
Signing in release mode
v Eclipse has a tool called Export Wizard
§  File > Export
§  Export Android Application
§  Select your key and preferences
§  Application is compiled, signed and aligned, ready to be
deployed
v Keep your private key safe
§  Use a strong password
§  Don't lend it to anyone
Luca Bedogni, Marco Di Felice
-
Programming with Android – SDK install and initial setup
34
Scarica

Luca Bedogni Marco Di Felice - Dipartimento di Informatica