Android开发教程(十)——android程序建立过程

一个android程序建立过程包括:建立工程、编码、编译、打包、签名、运行。

 

 

android工程:

src/
包含 Activity 文件, 存放在   src/your/package/namespace/ActivityName.java. 所有源代码文件 (例如 .javaor .aidl files)

bin/

编译输出目录。在这里你可以找到打包文件(.apk)和编译后的资源。
jni/
包含用adroid ndk开发的本地代码。

gen/

包含由ADT工具(aapt、aidl)产生的java文件。例如:  R.java 和从AIDL建立的接口文件。

assets/

This is empty. You can use it to store raw asset files. Files that you save here are    compiled into an .apk file as-is, and the original filename is preserved. You can navigate this    directory in the same way as a typical file system using URIs and read files as a stream of    bytes using the AssetManager. For example, this is a good    location for textures and game data.
res/
      包含应用程序的资源,例如: drawable files, layout files, and string values.
anim/
For XML files that are compiled into animation objects. See the  Animation resource        type.
color/
For XML files that describe colors. See the  Color Values resource        type.
drawable/
For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe        Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or        focused). See the Drawable resource type.
layout/
XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.
menu/
For XML files that define application menus.        See the  Menus        resource type.
raw/
For arbitrary raw asset files. Saving asset files here instead of in the         assets/ directory only differs in the way that you access them. These files        are processed by aapt and must be referenced from the application using a resource        identifier in the R class. For example, this is a good place for media, such as MP3        or Ogg files.
values/
For XML files that are compiled into many kinds of resource. Unlike other resources in        the res/ directory, resources written to XML files in this folder are not        referenced by the file name. Instead, the XML element type controls how the resources is        defined within them are placed into the R class.
xml/
For miscellaneous XML files that configure application components. For example, an XML        file that defines a PreferenceScreen, AppWidgetProviderInfo, or Searchability        Metadata. See Application Resources        for more information about configuring these application components.
libs/
包含私有库
AndroidManifest.xml
The control file that describes the nature of the application and each of its components.    For instance, it describes: certain qualities about the activities, services, intent receivers,    and content providers; what permissions are requested; what external libraries are needed; what    device features are required, what API Levels are supported or required; and others. See the     AndroidManifest.xml    documentation for more information
project.properties
This file contains project settings, such as the build target. This file is integral to    the project, so maintain it in a source revision control system. To edit project    properties in Eclipse, right-click the project folder and select     Properties.
local.properties
Customizable computer-specific properties for the build system. If you use Ant to build    the project, this contains the path to the SDK installation. Because the content of the file    is specific to the local installation of the SDK, the local.properties should not be maintained in a source revision control system. If you use Eclipse, this file is not used.
ant.properties
Customizable properties for the build system. You can edit this file to override default    build settings used by Ant and also provide the location of your keystore and key alias so that    the build tools can sign your application when building in release mode. This file is integral    to the project, so maintain it in a source revision control system. If you use Eclipse, this    file is not used.
build.xml

The Ant build file for your project. This is only applicable for projects that    you build with Ant.

 

建立过程:

 

 

典型的编译过程:

  • aapt( Android Asset Packaging Tool): 把你的应用程序资源文件(例如:  AndroidManifest.xml file and the XML files for your Activities),编译成R.java 。它可以让你从java代码中引用你的资源。
  • aidl :转换.aidl 接口成为java接口
  • java编译工具(javac):所有的java代码(包括 :java源码,R.java , .aidl 转换后的接口文件)由java编译工具(javac) 编译成中间代码(.class) 文件。
  • dex工具(dx):转换中间代码和第三方库的中间代码为Dalvik byte code
  • apk建立工具:把所有不需要编译的资源(例如:图片),编译的资源和Dalvik代码(.dex)打包成 .apk 文件
  • 签名(jarsigner).apk 建立后,它必须被签名才能安装到设备上,否则设备会拒绝安装。因为编译工具包含了调试签名的私钥,所以在编译时就直接签名了。但是你要发行版本时,你必须自己对apk包进行签名。
  • 对齐工具(zipalign):最后,还需要用zipalign工具对包进行对齐。

签名:

签名分两个部分:

  1. 生成私钥

    keytool:

    Keytool 选项描述
    -genkey产生一个键值对(公钥和私钥)
    -v允许动作输出
    -alias <alias_name>键的别名。只有前八位字符有效。
    -keyalg <alg>产生键的加密算法。支持DSA和RSA。
    -keysize <size>产生键的长度。如果不支持,keytool用默认值1024 bits.通常我们用2048 bits 或更长的key。
    -dname <name>

    专有名称,描述谁创建的密钥。该值被用作自签名证书的颁发者和主题字段。注意你可以不在命令行指定。如果没有指定keytool会提示你(CN, OU, and so on)。

    -keypass <password>

    键的密码。

    主要为了安全起见,如果没提供,keytool会提示你输入。

    -validity <valdays>

    键的有效期,单位:天

    Note: A value of 10000 or greater is recommended.

    -keystore <keystore-name>.keystore用于存储私钥的文件。
    -storepass <password>

    私钥存储文件的密码。

    主要为了安全起见,如果没提供,keytool会提示你输入。这个密码不会存储在你的shell历史记录中。

     keytool -genkey --keystoreHello.keystore -alias HelloWorld-keyalg RSA -keysize2048-validity10000

  2. 用私钥进行签名

    jarsigner:

    Jarsigner 选项描述
    -keystore <keystore-name>.keystore包含你私钥的存储文件
    -verbose显示输出动作。
    -sigalg签名算法,用 SHA1withRSA.
    -digestalg消息摘要算法,用 SHA1.
    -storepass <password>

    存储文件的密码。

    主要为了安全起见,如果没提供,jarsigner会提示你输入。这个密码不会存储在你的shell历史记录中。

    -keypass <password>

    私钥的密码。

    主要为了安全起见,如果没提供,jarsigner会提示你输入。这个密码不会存储在你的shell历史记录中。

    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1-keystore Hello.keystore my_application.apk HelloWorld

用eclipse工具:

 在工程上点右键->android tools->export singedappplication package

 

新建key存储文件

身份信息:

签名:

 

 

用已经存在的KEY存储文件签名:

 

 

对齐工具(zipalign):

一旦你已经签署了APK与你的私钥,在文件上运行zipalign。此工具可确保所有未压缩的数据开始于一个特定的字节对齐,相对于文件的开始。当一个设备上安装,确保对齐在4字节边界提供了性能优化。当对齐,Android系统能够读取文件使用mmap(),即使它们包含与对齐限制二进制数据,而不是复制所有从包中的数据的。其好处是在RAM中的运行应用程序所消耗的量减少。

zipalign -4 HelloWorld.apk HelloWorld_Release.apk

 

参考:

android的编译过程

apk包签名

对齐工具(zipalign)

转载地址:http://blog.csdn.net/kl222/article/details/17072357

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值