在前面的文章中我们使用Android Studio创建了签名用于APK文件的构建,这篇文章我们将使用keytool直接创建keystore,然后来验证APK构建是否正常,以及构建后的APK文件是否能够正常安装和使用。
本文使用的keystore文件的创建可参看如下文章:
- https://liumiaocn.blog.csdn.net/article/details/103578802
详细的keytool使用方法可参看:
- https://blog.csdn.net/liumiaocn/article/details/61921014
执行命令:keytool -genkey -alias release_v2_private_key -keypass liumiao -keyalg RSA -keysize 2048 -validity 25 -keystore keystoreByKeytool.jks -storepass liumiao
liumiaocn:Demo liumiao$ keytool -genkey -alias release_v2_private_key -keypass liumiao -keyalg RSA -keysize 2048 -validity 25 -keystore keystoreByKeytool.jks -storepass liumiao What is your first and last name? [Unknown]: Miao Liu What is the name of your organizational unit? [Unknown]: unicorn What is the name of your organization? [Unknown]: devops What is the name of your City or Locality? [Unknown]: DaLian What is the name of your State or Province? [Unknown]: LiaoNing What is the two-letter country code for this unit? [Unknown]: CN Is CN=Miao Liu, OU=unicorn, O=devops, L=DaLian, ST=LiaoNing, C=CN correct? [no]: yes Warning: The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore keystoreByKeytool.jks -destkeystore keystoreByKeytool.jks -deststoretype pkcs12". liumiaocn:Demo liumiao$ ls keystoreByKeytool.jks keystoreByKeytool.jks liumiaocn:Demo liumiao$使用此keystore创建证书
选择Build菜单的Generate Signed Bundle / APK…菜单选项
选择APK,点击Next按钮
选择刚刚使用keytool创建的keystore,并输入创建时使用的密码,然后点击Next按钮
做如下设定,然后点击Finish按钮开始构建
生成的apk结果文件确认
liumiaocn:Demo liumiao$ ls -l release/ total 3808 -rw-r--r-- 1 liumiao staff 1945533 Dec 18 20:13 app-release.apk -rw-r--r-- 1 liumiao staff 234 Dec 18 20:13 output.json liumiaocn:Demo liumiao$APK文件分析结果
上述APK在网易MUMU安卓模拟器上成功安装
打开Demo应用也能正常显示信息
不使用Android Studio本身的界面创建keystore,直接使用keytool创建,验证结果也是一样的,所以只需要提供符合keystore格式的签名文件即可满足Android的APK文件构建需要。