Chinaunix

标题: 开发者眼中的Google's Android开发包 [打印本页]

作者: Send_linux    时间: 2007-11-19 13:33
标题: 开发者眼中的Google's Android开发包
来源:linuxdevice

On Monday, November 12, 2007,Google released Android, a complete Linux based software stack aimeddirectly at the cell phone marketplace. I'll let others talk about whatit means for other players in the marketplace, the intricacies of GPL2vs the Apache License, etc. This article dives straight into the heartof the SDK and API itself, summarizing some of the documentationprovided by Google, then jumping into building an application usingAndroid.


Android Emulator
(Click to enlarge)


So, what Is Android?

Androidis a complete software stack for mobile devices such as cell phones,PDAs and high end MP3 players. The software stack is split into four layers:
Cellphone users obviously work with applications in the application layer.Android developers write those applications using the applicationframework. Unlike many embedded operating environments, Androidapplications are all equal -- that is, the applications that come withthe phone are no different than those that any developer writes. Infact, using the IntentFilterAPI, any application can handle any event that the user or system cangenerate. This sounds a bit scary at first, but Android has a wellthought-out security modelbased on Unix file system permissions that assure applications haveonly those abilities that cell phone owner gave them at install time.The framework is supported by numerous open source libraries such asopenssl, sqlite and libc. It is also supported by the Android corelibraries -- more on that in a second. At the bottom of the stack sitsthe Linux 2.6 kernel, providing the low level hardware interfaces thatwe all expect from a kernel. This is a Unix based system -- that is,the Unix C APIs are available -- but don't expect to drop to a shelland start executing shell scripts with your old friends grep and awk.Most of the Unix utilities are simply not there. Instead Androidsupplies a well thought out API for writing applications -- in Javausing the Android core libraries.

That's right, Androidapplications are almost exclusively written in Java. The Android corelibrary is a big .jar file that is supported by the Dalvik Virtual Machine-- a fast and efficient JVM work-alike that enables java-codedapplications to work on the Android cell phone. This is similar to, butnot the same as using Sun's JVM directly.

Building your development environment

Googleprovides three versions of the SDK; one for Windows, one for Mac OSX(intel) and one for Linux (x86). They also provide two developmentenvironments -- one is Eclipse based, and the other is a "roll yourown." The Eclipse based environment is quite feature-rich and shouldsuffice for most developers. There is no reason that you can't use bothEclipse and "roll your own."

If you get stuck in eclipse (like Idid), you may find yourself dropping to the command-line interfaces tosee what's really going on. However for this article, I'll assume thatyou're using the Eclipse IDE for your Android software developmentneeds. Once you've downloaded the Android SDK, Eclipse and the Eclipse Plugin, you should work through the first few sections of Google's install document (System and Software Requirements, Installing the SDK, Installing the Eclipse Plugin). I'd leave the rest of the document for later as it does get quite detailed quickly.

Read the Friendly Manual

Googlehas done a good job of writing a lot of documentation for Android.However, there isn't a great way of knowing what's important to readnow vs. what can wait. Here are some links to documents that areimportant to understand what Android is and how to develop applicationsusing it. If you read them in the order listed, then you'll gainunderstanding more quickly as you read increasingly detailed documents.Note that a lot of the documentation is available both onlineand in the SDK_ROOT/docs/index.html directory on your machine. If youhave a fast enough connection, I would suggest using the on-lineversions since they will be more up to date.

Here's the order in which I suggest you read the documentation:
Note:I had a problem here. The first time I ran the application, it workedfine. However on subsequent runs my application would not appear on theemulator. I killed and restarted the emulator, killed and restartedeclipse several times -- no joy. Finally, somewhat frustrated, I wasgoing to re-install everything. However before I did, I found aninvisible instance of the Android Debug Bridge (adb)running. I killed it and everything worked again. I thought I had toclose the emulator after each run of an application, but this turns outnot to be the case. When I closed the emulator after my first run, itleft the instance of adb running, which interfered with the subsequentinstances.
There's a lot of documentation, but if flows together nicely, reflecting the architecture of the environment.

Dissecting the SDK

WheneverI download an SDK, I like to take a look at the files I've installed.Often, there is a wealth of information hidden in the SDK itself thatis not readily visible from the documentation. So here's what you'llfind in the Android SDK on a Windows machine:
Exercising the SDK

Nowthat you have read the documentation and set up and debugged a simpleproject, it's time to look at some real code. Since Google has providedus with several sample applications, the best place to begin is byexamining them.
Repeatfor the other applications in the samples directory. This exerciseshould only take a few minutes -- besides, the Snake game is fun too!If you've taken the time to go through the Notepad Application Tutorial,then you'll be familiar with the NotePad sample -- however, the NotePadsample is fully developed and has features beyond the NotePad developedduring the Tutorial.

A File System Explorer Application

Finally,we'll use our new understanding of the Android to develop a simple filesystem explorer. The version in this article is pretty simple, but itcan serve as a jumping-off point for a more serious application downthe road.

Design

Before we start writing code, let's think about what a reasonable MP3 player should do. It should
    Process

Thisarticle will only cover Phase I of the project -- but when we're done,we'll have a functional file system explorer in just a few dozen linesof code.

To proceed with this hands-on example, click here.


New Android Project
(Click to enlarge)

It works!

Ifyou clicked above to follow the hands-on example, you found that inabout twenty lines of Java, and a small amount of XML, you've created auseful little application that will allow you to explore the Android'sfile system. For example, I found the ringtones in/system/media/audio/ringtones, as shown below.


Oooh, ringtones
(Click to enlarge)


AsI mentioned in the design section, a lot can be done with thisapplication, and we've hardly touched the surface of what you can dowith the Android application environment. There's thee billion cellphones out there. I suspect Google will get their fair share of them,so start cranking out code!

Conclusion

Android isa well-engineered development environment. Writing an Eclipse plug-inwas a smart move by Google -- one that should be emulated by other SDKdevelopers. Eclipse gives a developer and environment where he canreally think about the business problem without worrying about theboring details. Adding the functionality of the plugin helps developersjust sit down and start coding -- without having to worry about all theins and outs of configuration files and the like.

Dislikes

Androidis brand new to the general developer's world. As I write this, it'sWednesday, and the SDK came out on Monday of this week. Since it'sbrand new, there are some little problems that will have to be solvedin the coming releases.
Likes

Theres a lot to like about Android:


About John Lombardo-- John Lombardo has been a software engineer for more years than hecares to count. Recently he's been working on various Linux systemsthat are deeply embedded into diverse hardware platforms includingnetowork routers, helicopters and tanks. Regarding this article, Johncan be reached via email, [email=johnlombardo+Android-20071115@gmail.com]here[/email].

作者: benlan    时间: 2007-11-19 21:22
继续等待 Android  源码的开放,希望google的工程师说话算话,在google手机推出时,android的代码会放出
等着android和j2me的融合,希望java的统一,j2me,phoneme等项目已经做得非常好了,不要另搞一套,损人也不利己
作者: ilovecailin    时间: 2007-11-20 10:29





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2