setenv: warn that the script is meant to be sourced, not executed
[android/android-app-development-getting-started.git] / android-app-development-getting-started.sh
1 #!/usr/bin/env less
2 #
3 # Tutorial about getting started with android App development from the command
4 # line shell.
5 #
6 # Similar to
7 # http://vishalraj.in/blogs/hello-world-writing-my-first-android-app-on-linux
8 #
9
10 # The base working dir is assumed to be $HOME/Android
11 mkdir $HOME/Android
12 cd $HOME/Android
13
14 # Download and unpack the SDK from
15 # http://developer.android.com/sdk/index.html
16 wget http://dl.google.com/android/android-sdk_r21.1-linux.tgz
17 tar xzvf android-sdk_r21.1-linux.tgz
18
19 # Add "platform-tools" and "tools" to the PATH
20 export ANDROID_HOME=$HOME/Android/android-sdk-linux
21 export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools
22
23 # List packages
24 android list sdk --extended
25
26 # Install packages. Use this same command line to update the packages
27 android update sdk --no-ui --filter platform-tools,android-17,sys-img-17,extra-android-support
28
29 # Check what targets are available
30 android list targets
31
32 # Create an Android Virtual Device (AVD)
33 android create avd --target android-17 --name android-17-x86 --abi x86
34
35 # Install "ant" to build packages
36 sudo aptitude install ant
37
38 # Create a Hello World application
39 # http://developer.android.com/tools/projects/projects-cmdline.html
40 mkdir $HOME/Android/Apps
41 android create project \
42         --target android-17 \
43         --name MyFirstApp \
44         --path $HOME/Android/Apps/MyFirstApp \
45         --activity MainActivity \
46         --package com.example.myfirstapp
47
48 # And maybe you want to use git for your App?
49 cd $HOME/Android/Apps/MyFirstApp
50 ant clean
51 git init
52 git add .
53 git rm local.properties
54 git commit -m $'Initial import\n\nhttp://developer.android.com/training/basics/firstapp/creating-project.html'
55 echo "bin/" > .gitignore
56 echo "gen/" > .gitignore
57 echo "local.properties" > .gitignore
58 git add .gitignore
59 git commit -m "Add a .gitignore file"
60
61 # Learn how to write Android Apps:
62 http://developer.android.com/training/basics/firstapp/building-ui.html
63
64 # Build the App
65 # http://developer.android.com/tools/building/building-cmdline.html
66 cd $HOME/Android/Apps/MyFirstApp
67 ant debug
68
69 # Start the emulator, hardware accelerated:
70 # http://developer.android.com/tools/devices/emulator.html#vm-linux
71 emulator -verbose -avd android-17-x86 -scale 0.9 -gpu on -qemu -m 512 -enable-kvm
72
73 # Install the App into an Android [Virtual] Device
74 adb devices -l
75 adb -s emulator-5554 install bin/MyFirstApp-debug.apk
76
77 # Launch your application from the HOST
78 adb -s emulator-5554 -e shell am start -a android.intent.action.MAIN -n com.example.myfirstapp/com.example.myfirstapp.MainActivity
79
80 # See logs, e.g. only errors
81 adb -s emulator-5554 logcat *:E
82
83 # Connect to the emulator via telnet if needed
84 telnet localhost 5554
85