Android SDK 1.6 最主要改变为模拟器或真机可用系统自动创建的调试签名证书(debug.keystore), 但可发布的安装程序必须要先创建自签名证书
包括密钥库 keystore 和私钥 key alias 。
Android SDK 编译及安装程序主要有两个方法,(A) 用 Apache Ant (B) 用 Eclipse IDE。
首先介绍的 (A) Apache Ant
windows 方法
(1) 创建自签名证书
- cd C:\Android\
- "C:\Program
Files\Java\jdk1.6.0_16\bin\keytool.exe" -genkey -v -keystore
android-release-key.keystore -alias androidreleasekey -keyalg RSA
--validity 10000
|
回答以下问题
- Enter keystore password: <-- 设置keystore密码-必须至少6个字符
- 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=ipod4g, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=CN correct?
- [no]: yes <-- 输入 yes 确认
-
- Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 10,000 days
- for: CN=ipod4g, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=CN
- Enter key password for
- (RETURN if same as keystore password): <-- 设置key密码,如与keystore密码相同,回车
- [Storing android-release-key.keystore]
|
(2) Windows 进入command prompt 及更新 NotePad 项目
- cd C:\Android\Projects\samples
- android update project --name NotePad --target 2 --path NotePad
|
(3) 在 C:\Android\Projects\samples\NotePad 目录下建立 build.properties 文件, 内容如下
- # This file is used to override default values used by the Ant build system.
- #
- # This file must be checked in Version Control Systems, as it is
- # integral to the build system of your project.
- # The name of your application package as defined in the manifest.
- # Used by the 'uninstall' rule.
-
- application-package=com.example.android.notepad
-
- # The name of the source folder.
- #source-folder=src
-
- # The name of the output folder.
- #out-folder=bin
-
- # 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.
-
- key.store=C:/Android/android-release-key.keystore
- key.alias=androidreleasekey
|
(4) 必须先将手机上的USB调试(Debug)模式打开,在手机上执行
设置 -> 应用程序 -> 开发 -> USB 调试
Settings -> Applications -> Development -> USB debugging
(5) 手机连接到 USB, 检查设备代码和测试连接
如有多个装备连接时会看见
- List of devices attached
- HT99XXX99999 device
- emulator-5554 device
|
(6) 代码签名,编译程序 NotePad 项目 (這方法只適合 1.6 的编译程序,即第(2)点更新NotePad项目时使用 --target 2 的选项)
- cd C:\Android\Projects\samples\NotePad
- ant release
|
会要求输入keystore密码及key密码
- [input] Please enter keystore password (store:C:\Android\android-release-key.keystore):
- 输入keystore密码
- [input] Please enter password for alias 'androidreleasekey':
- 输入key密码
|
(7) 手机安装 NotePad 项目
方法一
- cd C:\Android\Projects\samples\NotePad
- ant install
|
方法二(如有多个装备连接时)
- cd C:\Android\Projects\samples\NotePad
- adb -s HT99XXX99999 install bin/NotePad-release.apk
|
HT99XXX99999 是第(5)点找到的设备代码
(8) 如需要重新编译程序及手机再安装 NotePad 项目
方法一
- cd C:\Android\Projects\samples\NotePad
- ant install
|
方法二(如有多个装备连接时)
- cd C:\Android\Projects\samples\NotePad
- adb -s HT99XXX99999 install -r bin/NotePad-release.apk
|
HT99XXX99999 是第(5)点找到的设备代码
(9) 如需要删除手机內 NotePad 项目
方法一
- cd C:\Android\Projects\samples\NotePad
- ant uninstall
|
方法二(如有多个装备连接时)
- adb -s HT99XXX99999 uninstall com.example.android.notepad
|
HT99XXX99999 是第(5)点找到的设备代码
方法三,用手机的一些管理程序例如: App Manager 或
设置 -> 应用程序 -> 管理应用程序,选择程序后删除
Settings -> Applications -> Manage applications 选择程序后删除
(10) 上面第(6)点如用于1.5的编译程序的签名方法如下
更新LunarLander项目时使用 --target 1 的选项
- cd C:\Android\Projects\samples
- android update project --name LunarLander --target 1 --path LunarLander
|
编译,签名及对齐
- cd C:\Android\Projects\samples\LunarLander
- ant release
- "C:\Program
Files\Java\jdk1.6.0_16\bin\jarsigner" -verbose -keystore
C:\Android\android-release-key.keystore -storepass mypassword -keypass
mypassword bin/LunarLander-unsigned.apk androidreleasekey
- zipalign -v 4 bin\LunarLander-unsigned.apk bin\LunarLander-release.apk
|
避免密码残留在历史上
- "C:\Program
Files\Java\jdk1.6.0_16\bin\jarsigner" -verbose -keystore
C:\Android\android-release-key.keystore bin/LunarLander-unsigned.apk
androidreleasekey
|
安装方法一
- cd C:\Android\Projects\samples\LunarLander
- adb install bin\LunarLander-release.apk
|
安装方法二(如有多个装备连接时)
- cd C:\Android\Projects\samples\LunarLander
- adb -s HT99XXX99999 install bin\LunarLander-release.apk
|
HT99XXX99999 是第(5)点找到的设备代码
mac / linux 方法
(1) 创建自签名证书
- cd ~/Android
- keytool -genkey -v -keystore android-release-key.keystore -alias androidreleasekey -keyalg RSA --validity 10000
|
回答以下问题
- Enter keystore password: <-- 设置keystore密码-必须至少6个字符
- 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=ipod4g, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=CN correct?
- [no]: yes <-- 输入 yes 确认
-
- Generating 1,024 bit RSA key pair and self-signed certificate (SHA1WithRSA)
- for: CN=ipod4g, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=CN
- Enter key password for
- (RETURN if same as keystore password): <-- 设置key密码,如与keystore密码相同,回车
- [Storing android-release-key.keystore]
|
(2) 进入 Terminal 及更新 NotePad 项目
- cd ~/Android/Projects/samples
- android update project --name NotePad --target 2 --path NotePad
|
(3) 在 ~/Android/Projects/samples/NotePad 目录下建立 build.properties 文件, 内容如下
- # This file is used to override default values used by the Ant build system.
- #
- # This file must be checked in Version Control Systems, as it is
- # integral to the build system of your project.
- # The name of your application package as defined in the manifest.
- # Used by the 'uninstall' rule.
-
- application-package=com.example.android.notepad
-
- # The name of the source folder.
- #source-folder=src
-
- # The name of the output folder.
- #out-folder=bin
-
- # 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.
-
- #linux
- #key.store=/home/ipod4g/Android/android-release-key.keystore
-
- #mac
- key.store=/Users/ipod4g/Android/android-release-key.keystore
- key.alias=androidreleasekey
|
(4) 必须先将手机上的USB调试(Debug)模式打开,在手机上执行
设置 -> 应用程序 -> 开发 -> USB 调试
Settings -> Applications -> Development -> USB debugging
(5) 手机连接到 USB, 检查设备代码和测试连接
如有多个装备连接时会看见
- List of devices attached
- HT99XXX99999 device
- emulator-5554 device
|
(6) 代码签名,编译程序 NotePad 项目 (這方法只適合 1.6 的编译程序,即第(2)点更新NotePad项目时使用 --target 2 的选项)
- cd ~/Android/Projects/samples/NotePad
- ant release
|
会要求输入keystore密码及key密码
- [input] Please enter keystore password (store:/Users/ipod4g/Android/android-release-key.keystore):
- 输入keystore密码
- [input] Please enter password for alias 'androidreleasekey':
- 输入key密码
|
(7) 手机安装 NotePad 项目
方法一
- cd ~/Android/Projects/samples/NotePad
- ant install
|
方法二(如有多个装备连接时)
- cd ~/Android/Projects/samples/NotePad
- adb -s HT99XXX99999 install bin/NotePad-release.apk
|
HT99XXX99999 是第(5)点找到的设备代码
(8) 如需要重新编译程序及手机再安装 NotePad 项目
方法一
- cd ~/Android/Projects/samples/NotePad
- ant install
|
方法二(如有多个装备连接时)
- cd ~/Android/Projects/samples/NotePad
- adb -s HT99XXX99999 install -r bin/NotePad-release.apk
|
HT99XXX99999 是第(5)点找到的设备代码
(9) 如需要删除手机內 NotePad 项目
方法一
- cd ~/Android/Projects/samples/NotePad
- ant uninstall
|
方法二(如有多个装备连接时)
- adb -s HT99XXX99999 uninstall com.example.android.notepad
|
HT99XXX99999 是第(5)点找到的设备代码
方法三,用手机的一些管理程序例如: App Manager 或
设置 -> 应用程序 -> 管理应用程序,选择程序后删除
Settings -> Applications -> Manage applications 选择程序后删除
(10) 上面第(6)点如用于1.5的编译程序的签名方法如下
更新LunarLander项目时使用 --target 1 的选项
- cd ~/Android/Projects/samples
- android update project --name LunarLander --target 1 --path LunarLander
|
编译,签名及对齐
- cd ~/Android/Projects/samples/LunarLander
- ant release
- jarsigner
-verbose -keystore ~/Android/android-release-key.keystore -storepass
mypassword -keypass mypassword bin/LunarLander-unsigned.apk
androidreleasekey
- zipalign -v 4 bin/LunarLander-unsigned.apk bin/LunarLander-release.apk
|
避免密码残留在历史上
- jarsigner -verbose -keystore ~/Android/android-release-key.keystore bin/LunarLander-unsigned.apk androidreleasekey
|
安装方法一
- cd ~/Android/Projects/samples/LunarLander
- adb install bin/LunarLander-release.apk
|
安装方法二(如有多个装备连接时)
- cd ~/Android/Projects/samples/LunarLander
- adb -s HT99XXX99999 install bin/LunarLander-release.apk
|
HT99XXX99999 是第(5)点找到的设备代码
(B) Eclipse IDE
(1) 在Package Explorer 选择程序項目,然后选择菜单 File -> Export...
(2) 打开 Android 文件夹,选择 Export Android Application,然后单击 Next
(3) 这将引导您的应用程序的签署,包括选择密钥库 keystore 和 key alias 私钥与其签署的步骤过程 (或创建一个新的密钥库 keystore 和私钥 key alias)
(4) 完成后你的应用程序 YourProgram-release.apk 将被编译(compiled),签署(signed),对齐(aligned) 并可安装及发布。安装或删除应用程方法请参考上面各点。
使用Andriod 编写完成的程序,要发布成可供手机真机使用的程序,需要三个步骤:
1.制作数字签名;
2.将数字签名绑定到需要发布的程序上;
3.安装供真机使用的APK文件;
下面对以上三个步骤进行说明:
1.制作数字签名
制作Andriod程序的数字签名需要使用JDK,先确认本机是否安装了JDK,在JDK目录下有一个KEYTOOL工具,这个就是制作数字签名使用到的工具;打开KEYTOOL
输入命令:keytool -genkey -v -keystore ophone.keystore -alias ophone -keyalg RSA -validity 1000
说明:-keystore ophone.keystore 表示生成的证书,可以加上路径(默认在用户主目录下);-alias ophone 表示证书的别名是ophone;-keyalg RSA 表示采用的RSA算法;-validity 1000表示证书的有效期是1000天。(Ophone注册程序有效期必须大于1年)
按如图步骤完成签名生成操作(注意中国缩写为CN)
完成上述操作在本地会生成一个扩展名为.keystore的文件,这个就是数字签名文件。
2.将数字签名绑定到需要发布的程序上
阅读(16494) | 评论(0) | 转发(0) |