å®è£
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" é项ï¼å
è®¸ä½ éæ©ä¸ä¸ªå·²åå¨ç项ç®ã
3ï¼ç¼è¾èªå¨çæç代ç ã
å½é¡¹ç®å建åï¼ä½ åæå建ç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ç模æå¨å°ä¼å¯å¨ï¼ä½ çåºç¨ç¨åºå°±ä¼è¢«æ¾ç¤ºåºæ¥ã
æ¤ä¸»é¢ç¸å
³å¾çå¦ä¸ï¼