转自:http://bbs.weiphone.com/read.php?tid=519993
开发Android第三步,签名证书,真机安装编译程序
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 <androidreleasekey>
- (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
- HT99XXX99999device
- emulator-5554device
|
(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 <androidreleasekey>
- (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
- HT99XXX99999device
- emulator-5554device
|
(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) 并可安装及发布。安装或删除应用程方法请参考上面各点。
.
- Android(安卓)WebView优化
- cocos2d-x 播放视频 on Android
- 《第一行代码》-第一次学习笔记(第一章).md
- android中如何通过代码来开启和关闭移动网络
- Android跨进程通信IPC之19——AIDL
- android 垂直 SeekBar 源代码(VerticalSeekBar)
- Android之Intent(一)
- Android(安卓)不得不知Tag的妙用
- Android中捕捉menu按键点击事件的方法
随机推荐
-
git 忽略未提交
-
使RPA效用最大化的业务流程应具备的5大特
-
基础命令8
-
第25章 0119-组件的知识,学习心得,笔记(Vue,
-
PHP基础知识:数组相关函数和操作
-
初探jQuery($(),attr(),css(),val(),html(
-
数组排序、数组合并
-
通讯录的实现
-
什么是爬虫?Python爬虫的工作流程怎样?
-
【我的Linux,我做主!】Docker容器技术基础