You are on page 1of 16

Google Android

SDK
Android SDK SDK

Download the Android SDK

Android SDK Android

Eclipse
Eclipse 3.2,3.3(Europa)
Android ()
IDE
JDK5.0 JDK6.0( JRE )

SDK
SDK zip SDK
$SDK_ROOT $SDK_ROOT/tools
1.Linux ~/.bash_profile ~/.bashrc PATH
$SDK_ROOT/tools PATH
export PATH=${PATH}:<$SDK_ROOT/tools >
2.Mac home .bash_profile Linux
.bash_profile
3.Windows
Path$SDK/tools
$SDK/tools adb
SDK PATH

Eclipse (ADT)
Eclipse Android Android Android
Development Tools(ADT)ADT
Android Android

Eclipse ADT
ADT Eclipse :
1. Eclipse Help > Software Updates > Find and Install....

2. Search for new features to install Next


3. New Remote Site
4.(Android Plugin)
URL OK
https://dl-ssl.google.com/android/eclipse/
5.() Finish
6. Search Results Android Plugin > Eclipse Integration > Android
Development Tools Next

7. Accept terms of the license agreement Next


8. Finish
9.ADT signed Install All
10. Eclipse
11. Eclipse Preferences SDK :
a. Window > Preferences... Preference Mac OS X:Eclipse > Preferences
b. Android
c. Browse... SDK
d. Apply, OK
ADT
ADT :
1. Help > Software Updates > Find and Install...
2. Search for updates of the currently installed features Finish
3. ADT
hello Android
Android SDK Eclipse 3.2 3.3

, "Hello, World"
1, File -> New -> Project "Android Project"
2,
3,

1 Android
Eclipse, File -> New -> Project , Android Eclipse
"Android Project"

Android Project,Next
2, .

:
Project Name:
Package Name: JAVA
"com.google.android",
Activity Name: Android Activity Activity

Application Name:
"""Use default location"


HelloAndroid .
public class HelloAndroid extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
}
}

[]

public class HelloAndroid extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
import android.widget.TextView;
Android , Views View

() View TextView.
TextView:
TexiView tv = new TextView(this);
TextView Android Context , Context ,
,

Activity Context HelloAndroid Activity


Context "this" TextView
TextView :
tv.setText("Hello, Android");
TextView
setContentView(tv);
Activity setContentView() View Activity , Activity

TextView

: Hello, Android
Android Eclipse Run -> Open Run Dialog

,"Android Application" , ()
"Android Application" ,
"New_configuration".

"Hello, Android", Browser (


Eclipse ), Activity
"Activity""Hello, Android"

"Apply" ,

"Run" Android

XML Android

XML
"Hello, World"

View

Android : XML

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello, Android"/>
AndroidXML View
, TextView View
View
Web

XML :

xmlns:android XML , Android ,


XML Android
android:layout_width View
android:layout_height View
android:text TextView Hello,
Android
XML res/ res
resources XML
Eclipse res
layout. main.xml,
R.java

public final class R {


public static final class attr {
};
public static final class drawable {
public static final int icon=0x7f020000;
};
public static final class layout {
public static final int main=0x7f030000;
};
public static final class string {
public static final int app_name=0x7f040000;
};
};
R.java
Eclipse IDE

layoutmain,
XML R.java R.java

HelloAndroid XML

public class HelloAndroid extends Activity {


/** Called when the activity is first created.
@Override
*/
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
}
R.java

Eclipse Android Eclipse


bug HelloAndroid
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Object o = null;
o.toString();
setContentView(R.layout.main);
}
}
NullPointerException

Object o = null; ( Eclipse


), Run -> Debug
Eclipse