相反於此篇(使用ant手動產生unsign apk), 現在必須使用ant手動產生 sign apk, 以步驟為說明
Step1. Generate keystore by command
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Note:alias_name 為 key 名稱, 必須相同於Step3. 的alias_name, 10000為有效時間(天數),官方建議25年以上
執行後還需要填入相關訊息如下
輸入 keystore 密碼: xxxabcdefg 重新輸入新密碼: xxxabcdefg 您的名字與姓氏為何? [Unknown]: test 您的編制單位名稱為何? [Unknown]: test 您的組織名稱為何? [Unknown]: test 您所在的城市或地區名稱為何? [Unknown]: test 您所在的州及省份名稱為何? [Unknown]: test 該單位的二字國碼為何 [Unknown]: test CN=test, OU=test, O=test, L=test, ST=test, C=test 正確嗎? [否]: y 針對 CN=test, OU=test, O=test, L=test, ST=test, C=test 產生有效期為 10,000 天的 2,048 位元 RSA 金鑰對以及自我簽署憑證 (SHA1withRSA) 輸入 <alias_name> 的主密碼 (RETURN 如果和 keystore 密碼相同):
完成後在當前目錄下會產生名稱為 my-release-key 的 keystore, 注意此keystore必須小心保存放在本機端
Step2. Create build.xml
(move to root folder of your project and type follow command)
android update project -p .
Note :
1.”android” means android tool at sdk, maybe need to indicate path like /android_sdk/tools/android
2. build.xml is for ant to build project
Step3. Create ant.properties and type follow content inside
(move to root folder of your project and type follow content)
key.store=/your-keystore-path/my-release-key.keystore key.alias=alias_name
Note:
1. alias_name must the same with Step1.
2. ant.properties be used by build.xml
Step4. Create custom_rules.xml
(move to root folder of your project and type follow content)
<?xml version="1.0" encoding="UTF-8"?> <project name="custom_rules" default="help"> <property file="/path_of_secure.properties/secure.properties" /> </project>
Note:
1. custom_rules.xml be used by build.xml
Step5. Create secure.properties reference follow content
key.store.password=xxxabcdefg key.alias.password=xxxabcdefg
Note:
1. password must equal to Step1. 的 “輸入 keystore 密碼”
2. path of secure.properties must the same with Step4. “/path_of_secure.properties/secure.properties”
3. this file maybe can put the same folder with my-release-key.keystore
Step6. type follow command
ant release
Note:
1. xxx-release.apk will be created at /project/bin/ when build process is success
2. build error :
/bin/AndroidManifest.xml:2: error: Error: String types not allowed (at ‘versionCode’ with value ‘${MAJOR_NUMBER}’).
solution:
Type normal string value e.g. “0” for vsersionCode and “0.1” for versionName at /bin/AndroidManifest.xml