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,打开应用程序列表,选择并运行你的应用程序。

没有评论: