Step 1:
D:\projects\Phonegap\Example> cordova plugin rm org.apache.cordova.console --save
添加--save
,这样它就会从config.xml
文件中删除插件.
Step 2:
要为Android生成发布版本,我们首先需要对platforms/Android中的AndroidManifest.xml
文件做一个小的更改.编辑文件并更改行:
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
并将android:debuggable
更改为false
:
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
从Cordova 6.2.0开始,完全删除了android:debuggable标签.以下是cordova 的解释:
"HardcodedDebugMode"类型问题说明:
最好从 list 中省略android:debuggable属性.
如果您这样做了,那么工具将自动插入android:debuggable=true
生成APK以在仿真器或设备上进行调试时.当你
执行发布版本,例如导出APK,它会自动设置
将其设置为False.
另一方面,如果您在 list 文件中指定了特定值,
那么工具就会一直使用它.这可能会导致意外发布
您的应用程序中包含调试信息.
Step 3:
现在我们可以告诉Cordova生成我们的发布版本:
D:\projects\Phonegap\Example> cordova build --release android
然后,我们可以在platforms/android/ant-build
中找到未签名的APK文件.在我们的例子中,文件是platforms/android/ant-build/Example-release-unsigned.apk
Step 4:
注意:我们在这个Git回购中有我们的keystore keystoreNAME-mobileapps.keystore
,如果您想创建另一个,请继续执行以下步骤.
密钥生成:
语法:
keytool -genkey -v -keystore <keystoreName>.keystore -alias <Keystore AliasName> -keyalg <Key algorithm> -keysize <Key size> -validity <Key Validity in Days>
EGS:
keytool -genkey -v -keystore NAME-mobileapps.keystore -alias NAMEmobileapps -keyalg RSA -keysize 2048 -validity 10000
keystore password? : xxxxxxx
What is your first and last name? : xxxxxx
What is the name of your organizational unit? : xxxxxxxx
What is the name of your organization? : xxxxxxxxx
What is the name of your City or Locality? : xxxxxxx
What is the name of your State or Province? : xxxxx
What is the two-letter country code for this unit? : xxx
然后生成了名为mobileapps的密钥存储.密钥库
Step 5:
将生成的密钥库放入
旧版cordova
D:\projects\Phonegap\Example\platforms\android\ant-build
新版本cordova
D:\projects\Phonegap\Example\platforms\android\build\outputs\apk
要对未签名的APK进行签名,请运行jarsigner工具,该工具也包含在JDK中:
语法:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <keystorename> <Unsigned APK file> <Keystore Alias name>
EGS:
D:\projects\Phonegap\Example\platforms\android\ant-build> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore Example-release-unsigned.apk xxxxxmobileapps
或
D:\projects\Phonegap\Example\platforms\android\build\outputs\apk> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore Example-release-unsigned.apk xxxxxmobileapps
Enter KeyPhrase as 'xxxxxxxx'
这是APK就位的签名.
Step 6:
最后,我们需要运行zip align工具来优化APK:
D:\projects\Phonegap\Example\platforms\android\ant-build> zipalign -v 4 Example-release-unsigned.apk Example.apk
或
D:\projects\Phonegap\Example\platforms\android\ant-build> C:\Phonegap\adt-bundle-windows-x86_64-20140624\sdk\build-tools\android-4.4W\zipalign -v 4 Example-release-unsigned.apk Example.apk
或
D:\projects\Phonegap\Example\platforms\android\build\outputs\apk> C:\Phonegap\adt-bundle-windows-x86_64-20140624\sdk\build-tools\android-4.4W\zipalign -v 4 Example-release-unsigned.apk Example.apk
现在我们有了名为example的最终版本二进制文件.apk,我们可以在谷歌Playstore 发布.