Thursday, March 29, 2012

Android Programming 101

1. Install Eclipse
2. Install the SDK: http://developer.android.com/sdk/installing.html
3. Install the ADT Plugins for Eclipse: http://developer.android.com/sdk/eclipse-adt.html#installing

4. You should see an Android button in you Eclipse menu. Click -> open Android Virtual Device Manger

5. Press New button to create a new Android Virtual Device (AVD)

6. Start your AVD

7. Open a shell, type $ which adb 
if you didn't see the adb bin file path, you need to add the SDK tools path to the $PATH environment variable. 
Add 
export PATH=/Users/username/Desktop/android-sdk-macosx/platform-tools:$PATH
to the ~/.profile 

8. $adb devices
you should see the list of available devices connected to the machine including the AVD we just started. 

9. $adb shell
It will start a shell which running in your device. You can run commands in the shell. 

10. Some interesting commands in Android Shell:
# id // shows username
# su // change to root when your device is rooted.
# logcat // shows the system log message
# cd /sdcard // this is the sdcard directory. Mounted from /mnt/sdcard. For emulator, you specify the size. when you create the new Android Virtual Device.
e.g. if you take a picture, the picture should be in the file /sdcard/DCIM/
if you want to copy something from your local machine to device, you could run $adb push filename. Then the file will saved in the sdcard directory
If you type run #mount in your Android device, you will see some block will be ready only. For example, the /system directory is read only. 
/device/block/mtdblock0 /system yaffs2 ro 0 0

11. you will find out a lot of Linux commands cannot run in Android shell, you can install busybox to solve this problem

12. If your phone is locked by a password, you could login from command:
$adb shell login <password>

13. if you want to get a file from android device, you could run:
$adb pull /mnt/sdcard/filename

14. if you want to install an .apk app to the android
$ adb install app.apk

15. All the installed application are stored at /data/app

16. if you want to debug the crashed application
$ adb logcat | tee logcat.file

No comments: