2008年10月29日星期三

Android SDK -- Developing Android Applications with Other IDEs and Tools

Developing Android Applications with Other IDEs and Tools
使用其它工具开发Android应用程序(Apache ant)

The recommended way to develop an Android application is to use Eclipse with the ADT plugin. This plugin provides editing, building, and debugging functionality integrated right into the IDE.

推荐的开发方式为Eclipse加ADT插件。ADT插件提供编辑、编译和调试功能并整合到IDE环境中。

However, if you'd rather develop your application in another IDE, such as IntelliJ, or use Eclipse without the ADT plugin, you can do that instead. The SDK provides the tools you need to set up, build, and debug your application.

如果你更愿意使用其它IDE,也是可以的。SDK提供工具来建立、调试你的应用程序。

Creating an Android Project

创建一个Android工程

The Android SDK includes activityCreator, a program that generates a number of stub files for your project, as well as a build file. You can use the program to create an Android project for new code or from existing code, such as the sample applications included in the SDK. For Linux and Mac, the SDK provides activityCreator.py, a Python script, and for Windows, activityCreator.bat, a batch script. Regardless of platform, you can use activityCreator in the same way.

activityCreator是SDK提供的一个用于生成一系列stub files(桩文件)的程序。你可以使用它创建一个新工程或从已存在的code创建一个工程(比如SDK提供的sample)。对linux或Mac而言,activityCreator是一个Python脚本。

To run activityCreator and create an Android project, follow these steps:

使用activityCreator创建一个工程的过程如下:
1. In the command line, change to the tools/ directory of the SDK and create a new directory for your project files. If you are creating a project from existing code, change to the root folder of your application instead.

1、打开一个终端,切换${Android_SDK_DIR}/tools为当前工作目录,为你的工程创建一个目录(mkdir)这里假设为./helloActivity。如果你是为一个已存在的code创建一个工程,可以切换到该code的根目录下(不建议这样做,我的观点是只要是新工程都应该拥有一个新目录,至于code,可以拷贝过去)。

2. Run activityCreator. In the command, you must specify a fully-qualified class name as an argument. If you are creating a project for new code, the class represents the name of a stub class that the script will create. If you are creating a project from existing code, you must specify the name of one Activity class in the package. Command options for the script include:

2、运行activityCreator。格式为activityCreator --out Project_Dir Your.Package.Name.ActivityName
例子如下:
liangtaohy@tools/# activityCreator --out helloActivity com.example.android.helloactivity

Package: com.example.android
Output directory: helloActivity
Activity name: helloactivity
Created directory /home/liangtaohy/sys/Android/android-sdk-linux_x86-1.0_r1/tools/helloActivity/src/com/example/android
Added file helloActivity/src/com/example/android/helloactivity.java
Created directory /home/liangtaohy/sys/Android/android-sdk-linux_x86-1.0_r1/tools/helloActivity/bin
Created directory /home/liangtaohy/sys/Android/android-sdk-linux_x86-1.0_r1/tools/helloActivity/libs
Created directory /home/liangtaohy/sys/Android/android-sdk-linux_x86-1.0_r1/tools/helloActivity/res/values
Added file helloActivity/res/values/strings.xml
Created directory /home/liangtaohy/sys/Android/android-sdk-linux_x86-1.0_r1/tools/helloActivity/res/layout
Added file helloActivity/res/layout/main.xml
Added file helloActivity/AndroidManifest.xml
Added file helloActivity/build.xml
activityCreator脚本生成如下的一些文件:
* AndroidManifest.xml:应用程序的manifest文件
* build.xml:一个Ant文件,通过它你可以build/package应用程序
* src/your/package/name/ActivityName.java:由你在命令行参数中指定的Activity类
* res/:资源存放目录
* src/:源文件目录
* bin/:build脚本生成的文件的存放目录

Building an Android Application
build一个Android应用程序

Use the Ant build.xml file generated by activityCreator to build your application.
使用命令ant build.xml来build你的应用程序,其中build.xml由activitycreator生成。
1.If you don't have it, you can obtain Ant from the Apache Ant home page. Install it and make sure it is on your executable path.
1、如果你没有安装ant工具,请访问http://ant.apache.org/。安装完后,请确认它在你的当前PATH中。

2.Before calling Ant, you need to declare the JAVA_HOME environment variable to specify the path to where the JDK is installed.
2、在运行命令ant之前,你需要声明JAVA_HOME环境变量,把它指定为你的JDK安装目录即可。

3.If you have not done so already, follow the instructions for Creating a New Project above to set up the project.

4.You can now run the Ant build file by simply typing ant in the same folder as the build.xml file for your project. Each time you change a source file or resource, you should run ant again and it will package up the latest version of the application for you to deploy.
4、在build.xml所在的目录下运行命令ant即可build你的project。

Running an Android Application
运行一个Android应用程序

To run a compiled application, you will upload the .apk file to the /data/app/ directory in the emulator using the adb tool as described here:
要运行一个编译过的应用程序,你需要上传.apk文件到模拟器的/data/app目录。adb工具帮助你完成此事。

1. Start the emulator (run /tools/emulator from the command line)
启动emulator
2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
导航emulator到home界面下。
3. Run adb install myproject/bin/.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to /sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
运行命令adb install /bin/.apk上传执行文件。
4. In the emulator, open the list of available applications, and scroll down to select and start your application.
进入emulator,打开应用程序列表,选择并运行你的应用程序。

2008年10月22日星期三

给内核打补丁

比如我的内核是2.6.25.1,补丁的版本为2.6.25.2,则可用下列命令打补丁:
#cd /usr/src/linux
patch -p 1 < patch-2.6.25.2

2008年10月21日星期二

gvfs-fuse-daemon困惑

我在学习linux系统管理时,使用命令df -T -h看到如下输出:

文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda8 ext3 31G 12G 17G 42% /
udev tmpfs 489M 112K 489M 1% /dev
/dev/sda1 ntfs 20G 8.5G 12G 44% /mnt/windows/c
/dev/sda5 ntfs 30G 5.7G 24G 20% /mnt/windows/d
/dev/sda6 vfat 15G 12G 2.8G 82% /mnt/windows/e
/dev/sda7 vfat 54G 20G 35G 36% /mnt/windows/f
df: “/var/lib/gdm/.gvfs”: 权限不够
gvfs-fuse-daemon
fuse.gvfs-fuse-daemon 31G 12G 17G 42% /home/liangtaohy/.gvfs

对gvfs-fuse-daemon很是困惑!它似乎是一个设备,挂在/home/liangtaohy/.gvfs上,占用的空间和/的完全相同!
我在IRCnet#linux channel中获得的解释是:
Gvfs is a userspace virtual filesystem where mount runs as a separate processes which you talk to via dbus. It also contains a gio module that seamlessly adds gvfs support to all applications using the gio API. It also supports exposing the gvfs mounts to non-gio applications using fuse.

大致理解为:gvfs是一个虚拟文件系统,mount在其上可以作为一个独立的进程与via dbus通讯。同时gvfs也包含一个Gio模块(gio是一个共享库,属于glib)。Gio负责提供操作gvfs的API接口。gvfs通过fuse支持非gio的应用。
gvfs支持sftp,ftp,smb,WebDAV,ObexFTP等。
gvfs的一个简单应用是挂载ftp到本地目录~/.gvfs上,如北邮人的software.edu.cn。截图如下:


图中的Nautilus版本为2.22.2

2008年10月19日星期日

2008年10月17日星期五

安装Thunderbird

OpenSUSE 11.0 下安装Thunderbird

比较喜欢这个Mail client,Windows下我也用这个。它的安装很简单。
1、下载Thunderbird,网址为:
www.mozilla.org.cn/thunderbird/
我下载的是2.0.0.9 for Linux i686,Chines(Simplified)(11MB)
2、解压
tar -zxvf thunderbird-2.0.0.9.tar.gz
mv thunderbird /usr/local/
3、创建启动器
这个很简单,桌面点右键。。。。