免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7200 | 回复: 2
打印 上一主题 下一主题

开发者眼中的Google's Android开发包 [复制链接]

论坛徽章:
49
15-16赛季CBA联赛之福建
日期:2016-06-22 16:22:002015年亚洲杯之中国
日期:2015-01-23 16:25:12丑牛
日期:2015-01-20 09:39:23未羊
日期:2015-01-14 23:55:57巳蛇
日期:2015-01-06 18:21:36双鱼座
日期:2015-01-02 22:04:33午马
日期:2014-11-25 09:58:35辰龙
日期:2014-11-18 10:40:07寅虎
日期:2014-11-13 22:47:15申猴
日期:2014-10-22 15:29:50摩羯座
日期:2014-08-27 10:49:43辰龙
日期:2014-08-21 10:47:58
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-19 13:33 |只看该作者 |倒序浏览
来源: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:
  • The application layer
  • The application framework
  • The libraries and runtime
  • The kernel
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:
      
  • What is Android? Explainswhat Android is and gives a high-level overview of its features andarchitecture. Don't dive into the links just yet -- just get a feel forthis overall document.
  • Read the Anatomy of an Android Applicationpage. This details the four building blocks of an Android app:Activity, Intent Receiver, Service and Content Provider. Again, don'tfollow the links just yet -- just get an overview of the architecture.You may want to reread sections on Activities and Intent Receivers --gaining an understanding of these concepts is critical to understandinghow to build an Android application. If you don't get it yet, you'llsee it again when you go through the Notepad Application Tutorial.
  • Next read the Development Tools document. Again -- just get a flavor, don't dive into the detail yet.
  • Read the Lifecycle of an Android Application page.
  • Now, finally, it's time to get your hands dirty. Work through the Hello Android page. Make sure you actually do it using Eclipse.
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.
      
  • Now go back and read the rest of the Installing the SDK document -- the bottom half of it details some great debugging tips and features.
  • Next, go through the Notepad Application Tutorial.This is where the rubber really meets the road. If you spend the timeto go through this series of exercises and really understand the code,you will be well on your way to becoming an Android expert.
  • Read the Developing Android Applicationspages. This will take some time -- these articles go into a lot ofdetail about several topics including how to implement the UI, datastorage/retrieval and the security model.
  • Finally, go back through this list and follow the links in the previous documents as topics interest you.
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:
      
  • android.jar- The Android application framework. Unzipping this jar reveals theentire class structure and all of the supporting classes of theframework. Currently there is no source.
  • docs - 100 megabytes worth of documentation, samples, etc.
  • samples - Six different sample applications - ApiDemos, HelloActivity, LunarLander, NotePad, SkeletonApp and Snake
  • tools - the various SDK binaries such as aapt, acp, and emulator live here.
    • lib - various templates and supporting jar files live in this directory
      • activityCreator - the activityCreator python application lives here.
      • images - The Linux file system images are found in this directory: ramdis.img, system.img and userdata.img. They are YAFFS2 file system images, so I couldn't open them without additional kernel support on my Fedora system.
        • skins - supporting emulator graphics for HVGA and QVGA screens in both landscape and portrait format.
           
        
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.
      
  • If you have not already done so, execute the first few sections of Google's install document. Stop after you've installed the Eclipse plugin successfully.
  • Now work through the Hello Androidpage if you haven't already. This will get you started working withAndroid applications and the debugger. Note that it's probably a goodidea to create a new workspace for your Android projects if you alreadyuse Eclipse.
  • Next we're going to set up Eclipseprojects for each of the sample applications. You can never have toomuch sample code. I'll walk through setting up the Lunar Lander exampleand leave it as an exercise to the reader to set up the rest.
    • Bringup the same Eclipse workspace that you used for the Hello Android, andclose the project (Right click on the project in packageexplorer->Close Project).
    • File->New->Android Project
    • Project Name: LunarLander
    • Click the "Create Project from existing source" radio button
    • Browseto the samples/LunarLander directory in the SDK. If you find the rightdirectory, the Properties fields will auto-fill with the correctinformation from the Package.
    • Click Finish
    • Bringup Eclipse's Console window (Window->Show View->Console) if it'snot already visible in a tab at the bottom of the screen. It will showyou the build process that Eclipse went through to create theapplication.
    • Create a Run Configuration: Run->Open Run Dialog
    • Highlight "Android Application" in the treeview to the left.
    • Click the "New button".
    • Name: Lunar Lander
    • Click the Browse button next to Project
    • Double-click the LunarLander project and hit OK
    • Click the down arrow for the Activity and choose the one and only Activity: com.google.android.lunarlander.LunarLander
    • Click Apply
    • Click Run
    • Switch to the Emulator and play a few rounds of Lunar Lander. Kinda fun.
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
      
  • Phase I features
    • Show a list of files and directories
    • Allow the user to navigate through the directory structure by clicking on directories
    • Warn the user that he has clicked on a file

      
  • Phase II features
    • Allow the user to display a dump of a file when it is clicked
    • Use a tree view instead of a simple list
    • Show a dialog box with the filesystem information (size, permissions, etc) when the user clicks on an icon next to each file
    • Give this application permissions to read any file on the file system

      
  • Phase III features
    • Do all of phase II with pretty graphics, such as thumbnails, nstead of boring dropdowns and list boxes
    • Execute applications that we understand, such as mp3 files
    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.
      
  • Many more examples for the APIs.
  • Amore thorough explanation of what does and does not work under theemulator. My first example application was a simple MP3 player.
  • Releasethe source code. This will make it a lot easier to debug Androidapplications, as well as write them in the style that the Googledevelopers wrote them.
Likes

Theres a lot to like about Android:
      
  • It's by Google -- so it has a company with some clout behind it.
  • ApplicationDevelopers write their code in Java. Since the learning curve for Javais much less than that of C/C++/ObjectiveC, there will be many manydevelopers who are eager to start writing applications for Android.
  • TheSDK and API are well designed. There is some complexity there, and as Imentioned, the Documentation needs improvement (Google: call me --but a well designed system is easier to understand and learn, evenwithout lots of great examples.


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].

论坛徽章:
0
2 [报告]
发表于 2007-11-19 21:22 |只看该作者
继续等待 Android  源码的开放,希望google的工程师说话算话,在google手机推出时,android的代码会放出
等着android和j2me的融合,希望java的统一,j2me,phoneme等项目已经做得非常好了,不要另搞一套,损人也不利己

论坛徽章:
0
3 [报告]
发表于 2007-11-20 10:29 |只看该作者
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP