Show me the code! – By Davanum Srinivas

November 13, 2007

Hello World using Ant for Google’s Android platform

Filed under: Uncategorized — Davanum Srinivas @ 10:46 am

Here’s a quick start of stuff i found poking around Android SDK this morning. The official Getting Started guide is here.

Run the activityCreator to generate a hello world project



C:\android\mysandbox>..\tools\activityCreator.bat --out HelloAndroid com.google.android.hello.HelloAndroid
package: com.google.android.hello
out_dir: HelloAndroid
activity_name: HelloAndroid
Created directory HelloAndroid\src\com\google\android\hello
Added file HelloAndroid\src\com\google\android\hello\HelloAndroid.java
Created directory HelloAndroid\bin
Created directory HelloAndroid\res\values
Added file HelloAndroid\res\values\strings.xml
Created directory HelloAndroid\res\layout
Added file HelloAndroid\res\layout\main.xml
Added file HelloAndroid\AndroidManifest.xml
Added file HelloAndroid\build.xml

Take a look at the generated files



C:\android\mysandbox>dir /s /b
C:\android\mysandbox\HelloAndroid
C:\android\mysandbox\HelloAndroid\AndroidManifest.xml
C:\android\mysandbox\HelloAndroid\bin
C:\android\mysandbox\HelloAndroid\build.xml
C:\android\mysandbox\HelloAndroid\res
C:\android\mysandbox\HelloAndroid\src
C:\android\mysandbox\HelloAndroid\res\layout
C:\android\mysandbox\HelloAndroid\res\values
C:\android\mysandbox\HelloAndroid\res\layout\main.xml
C:\android\mysandbox\HelloAndroid\res\values\strings.xml
C:\android\mysandbox\HelloAndroid\src\com
C:\android\mysandbox\HelloAndroid\src\com\google
C:\android\mysandbox\HelloAndroid\src\com\google\android
C:\android\mysandbox\HelloAndroid\src\com\google\android\hello
C:\android\mysandbox\HelloAndroid\src\com\google\android\hello\HelloAndroid.java

Build the project using ant



C:\android\mysandbox\HelloAndroid>ant
Buildfile: build.xml

dirs:
[mkdir] Created dir: C:\android\mysandbox\HelloAndroid\bin\classes

resource-src:
[echo] Generating R.java...

aidl:

compile:
[javac] Compiling 2 source files to C:\android\mysandbox\HelloAndroid\bin\classes

dex:

package-res:

package-res-no-assets:
[echo] Packaging resources...

package-dex:
[echo] Packaging dex...
[zip] Building zip: C:\android\mysandbox\HelloAndroid\bin\HelloAndroid.apk.tmp
[move] Moving 1 file to C:\android\mysandbox\HelloAndroid\bin

package:

BUILD SUCCESSFUL
Total time: 2 seconds

Look at the generated artifacts



C:\android\mysandbox\HelloAndroid>cd bin

C:\android\mysandbox\HelloAndroid\bin>dir
Volume in drive C is Preload
Volume Serial Number is D886-7853

Directory of C:\android\mysandbox\HelloAndroid\bin

11/13/2007 10:24 AM .
11/13/2007 10:24 AM ..
11/13/2007 10:24 AM classes
11/13/2007 10:24 AM 1,854 classes.dex
11/13/2007 10:24 AM 2,449 HelloAndroid.apk
2 File(s) 4,303 bytes
3 Dir(s) 48,294,133,760 bytes free

Start the emulator



C:\android\mysandbox\HelloAndroid\bin>start C:\android\tools\emulator

android-emulator.png

Install the generated artifact



C:\android\mysandbox\HelloAndroid\bin> C:\android\tools\adb install HelloAndroid.apk
153 KB/s (0 bytes in 2449.000s)

Look at the application in the emulator

android-apps.png

Remove the application



C:\android\mysandbox\HelloAndroid\bin>C:\android\tools\adb shell
# ls
ls
drwxr-xr-x root root 1969-12-31 19:00 var
drwxrwxrwt root root 2007-11-13 10:28 tmp
drwxr-xr-x root root 2007-11-11 15:59 system
drwxr-xr-x root root 1969-12-31 19:00 sys
drwxr-xr-x root root 1969-12-31 19:00 sbin
dr-xr-xr-x root root 1969-12-31 19:00 proc
-rwxr-xr-x root root 93824 1969-12-31 19:00 init
drwxr-xr-x root root 1969-12-31 19:00 etc
drwxrwx--x system system 2007-11-11 15:59 data
drwx------ root root 1969-12-31 19:00 root
drwxr-xr-x root root 2007-11-13 10:27 dev
# cd data
cd data
# cd app
cd app
# ls
ls
-rw-rw-rw- root root 2449 2007-11-13 10:24 HelloAndroid.apk
-rw-r--r-- system system 1325833 2007-11-11 15:59 ApiDemos.apk
# rm HelloAndroid.apk
rm HelloAndroid.apk
# exit
exit

6 Comments »

  1. Have you noticed how google android looks like iPhone operational system?
    Compare the functions shown in the videos below:
    weshow.com/us/p/23362/google_android_demo
    weshow.com/us/p/18795/iphone_home_made_review
    What do you think? Will google bring iPhone power to everyone who can’t afford apple products? That would be great😀

    Comment by Victor — November 14, 2007 @ 9:59 am

  2. >> Will google bring iPhone power to everyone who can’t afford apple products?

    More importantly than that, it will be wide open. So that developers can provide functionality that the market demands. There is no good reason why this shouldn’t revolutionize the cell phone industry.

    Comment by Mike — November 14, 2007 @ 12:43 pm

  3. I dont quite agree with Victor’s comments about similar functionality to iPhone. Android works on both the interfaces and for the developer its seamless…

    And the iPhone does not even have an SDK out ;)) lol

    Comment by Saptarshi — November 14, 2007 @ 1:34 pm

  4. […] Bem, o que dizer então? Android? Nah, isso merece um post por si só… (só um adendo, já tem gente gerando os builds de android no ant) […]

    Pingback by Retomada « Engenharia de software e dificuldades do dia-a-dia — November 14, 2007 @ 4:08 pm

  5. I wish to point out this article.

    Android First Example in Java: Hello World
    http://programmaremobile.blogspot.com/2009/01/android-first-example-hello-world.html

    It expain the steps(from java code to running into emulator) to make the first hello world without eclipse.
    I hope it is welcome!

    Comment by giuseppe — January 30, 2009 @ 7:06 am

  6. 15aq0a comment5 ,

    Comment by Agzvqkck — May 8, 2009 @ 3:57 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: