Reference/othertools

From Android中文网

Android中文网(androidcn.net) 版权申明 : creativecommons licenses
Jump to: navigation, search

目录

[编辑] 其他工具

下面将介绍几款我们在开发Android时非常有用的工具。

这些工具都存放在SDK得tools/目录下。


[编辑] mksdcard

(xing:因为google放出了video的demo,很多人开始查sd卡的用法,所以抽时间把这个翻译了一下。keywords:android create sdcard)

mksdcard工具是用来创建虚拟的SD卡映像的,它创建SD卡是FAT32格式。创建好的SD卡映像可以被载入模拟器,如同使用一个真正的SD设备。下面是它的用法:

   mksdcard [-l label] <size>[K|M] <file>

下面的表格列出了mksdcard所有的选项和参数

参数 注释
-l 为SD卡创建一个卷标。
size 用一个整数来设定SD卡的大小。缺省单位是byte,可以使用大写的"K"和"M"跟在数值后面改变这个单位,如 1048576K, 1024M(xing:有网友建议不要设置得太小,不然模拟器可能会崩溃。而且命令有提示,模拟器不能用8M的卡。我现在用32M没有任何问题。要注意一点,一旦生成映像,所有的空间都会被分配,就是说如果你使用了1024M作为参数,你的硬盘上就会出现一个1G的文件。)
file 映像的文件名。比如sdcard.img。
   例:mksdcard -l mycard 32M mycard.img 

创建了SD映像之后就可以在模拟器的启动参数里面加入-sdcard来载入它。更多信息参见[Android Emulator].

   emulator -sdcard <file>

(xing:文件名最好使用全路径,尤其是在eclipse里面,理论上将sdcard.img放在<system>下是可以载入的,但事实测的时候并没有成功。)

附:如何将文件放到SD卡中

如果你使用eclipse,那就再简单不过了。首先在run dialog里面为emulator增加启动参数-sdcard <file>,模拟器启动后,在ddms里面就可以看到sdcard这个目录了,然后使用文件传送按钮就可以把文件传到SD卡中。

使用命令行也不麻烦,首先还是要有启动参数,然后使用

  adb push <local> <remote>

就可以将本地文件发送到模拟器,例如:

 adb push temp.img /sdcard/audio

(xing:这个audio目录是使用adb shell创建的,好像在播放视频的时候,模拟器会自己创建video目录。)

[编辑] dx

The dx tool lets you generate Android bytecode from .class files. The tool converts target files and/or directories to Dalvik executable format (.dex) files, so that they can run in the Android environment. It can also dump the class files in a human-readable format and run a target unit test. You can get the usage and options for this tool by using dx -help.


[编辑] activityCreator

If you aren't using the Eclipse IDE and ADT plugin, you can use the the activityCreator script to get started with a new application. When you run the script, it creates the structure of a minimal Android application that you can build on and extend to meet your needs.

For Linux and Mac, the SDK provides activityCreator.py, a Python script, and for Windows activityCreator.bat, a batch script that runs an executable. Regardless of platform, the usage for the script is the same:

   activityCreator [--out <folder>] [--ide intellij] your.package.name.ActivityName
Option Description
--out <folder> Specifies where to create the files/folders.
--ide intellij Creates project files for IntelliJ

When run, the script creates these files:

  • AndroidManifest.xml -- The application manifest file.
  • build.xml -- An Ant script to build/package the application.
  • res -- The resource directory.
  • src -- The source directory.
  • src/your/package/name/ActivityName.java -- The Activity class.
  • bin -- The output folder for the compiled .apk (when built by Ant).

When you are ready, you can use Ant to build the project so that you can run it on the emulator.

If you are using Eclipse with the ADT plugin, you do not need to use activityCreator. You can use the New Project Wizard, provided by the ADT plugin, instead.

Personal tools