随笔 - 132  文章 - 51  trackbacks - 0
<2011年4月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

留言簿(7)

随笔分类

随笔档案

文章分类

文章档案

cocos2d-x

OGRE

OPenGL

搜索

  •  

最新评论

阅读排行榜

评论排行榜

Signing in Release Mode


When your application is ready for release to other users, you must:

  1. Obtain a suitable private key
  2. Compile the application in release mode
  3. Sign your application with your private key
  4. Align the final APK package
发布release版本要有4步
官方说明: 
 http://developer.android.com/tools/publishing/app-signing.html#releasecompile 


平时通过Eclipse生成在bin目录下的apk文件,都是debug版的,如何创建release版的软件呢? 
其实还是挺简单的。 

1. 通过java自带的keytool工具,创建release版的keystore 

keytool -genkey -v -keystore keystore_name.keystore -alias alias_name -keyalg RSA -validity 10000 


keystore_name.keystore:要创建的release版keystore的文件名 
alias_name:别名?取个好记点的名字吧,后面还要用到的 (填写配置文件)
-keyalg RSA:通过RSA算法生成 
-validity 10000:有效期,单位是天 

如果java环境配置正常,输入命令后会出现下列信息 
Enter keystore password:(keystore的密码) 
Re-enter new password:(确认keystore的密码) 
What is your first and last name? 
  [Unknown]:  (姓名,用自己喜欢的名字吧,不知道会显示在哪里) 
What is the name of your organizational unit? 
  [Unknown]:  (组织单位) 
What is the name of your organization? 
  [Unknown]:  (组织,不知道和上面那个有什么区别) 
What is the name of your City or Locality? 
  [Unknown]:  (城市) 
What is the name of your State or Province? 
  [Unknown]:  (州,省,县) 
What is the two-letter country code for this unit? 
  [Unknown]:  CN 
Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=CN correct? 
  [no]:  yes (确认输入的信息) 

Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with 
a validity of 10,000 days 
        for: CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=CN 
Enter key password for <alias_name> 
        (RETURN if same as keystore password):(alias的密码,如果和keytore密码一致,直接回车) 
Re-enter new password:(确认alias的密码) 
[Storing my-release-key.keystore] 


2.发布Release版本
Signing in Release Mode


When your application is ready for release to other users, you must:

  1. Obtain a suitable private key
  2. Compile the application in release mode
  3. Sign your application with your private key
  4. Align the final APK package
官方的步骤有4步,编译release版本的应用程序

2.1 Eclipse导出
在Eclipse中,右键要发布的项目,依次选择Android Tool -> Export Signed Application Package... 
然后就是step-by-step了,选择刚才生成的release版keystore,输入密码,选择alias,输入alias密码,生成release版的apk。 

2.2 采用ANT命令行形式

$ ant release

By default, the build script compiles the application APK without signing it. The output file in your project bin/ will be <your_project_name>-unsigned.apk. Because the application APK is still unsigned, you must manually sign it with your private key and then align it using zipalign. 

默认编译出来的版本是没有证书的<your_project_name>-unsigned.apk ,需要手动添加证书和对齐

To specify your keystore and alias, open the project ant.properties file (found in the root of the project directory) and add entries for key.store and key.alias. For example: 

我们可以在ant.properties文件中指定证书位置和对齐

# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
#  'source.dir' for the location of your java source folder and
#  'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
#  'key.store' for the location of your keystore and
#  'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

#我的证书在上一级目录下
#alias是创建证书时填写的alias_name

key.store=../keystore_name.keystore 
key.alias=alias_name

接下来的步骤很easy了

Save your changes. Now you can build a signed .apk in release mode:

  1. Open a command-line and navigate to the root of your project directory.
  2. Use Ant to compile your project in release mode:
    ant release
  3. When prompted, enter you keystore and alias passwords.

    Caution: As described above, your password will be visible on the screen.

This creates your Android application .apk file inside the project bin/ directory, named<your_project_name>-release.apk. This .apk file has been signed with the private key specified inant.properties and aligned with zipalign. It's ready for installation and distribution.

ant release后会生成一个<your_project_name>-release.apk的版本

啊,世界清静了~~~ 

最后就是安装了。 
由于使用了新的签名,必须先卸载原来安装的程序才可以安装。 


/////////////////////////////////////////////////////////////////////////////////////////////////////////////

常见问题:
生成的debug和release有什么区别 大小差不多

Support for a true debug build. Developers no longer need to add the android:debuggable attribute to the tag in the manifest — the build tools add the attribute automatically. In Eclipse/ADT, all incremental builds are assumed to be debug builds, so the tools insert android:debuggable="true". When exporting a signed release build, the tools do not add the attribute. In Ant, a ant debug command automatically inserts the android:debuggable="true" attribute, while ant release does not. If android:debuggable="true" is manually set, then ant release will actually do a debug build, rather than a release build. 




























posted on 2012-08-15 10:11 风轻云淡 阅读(2277) 评论(0)  编辑 收藏 引用 所属分类: cocos2d

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理