使用系统key文件生成keystore
1. 源码文件夹 android\build\target\product\security 包含四个标准key, 我们需要用到platform的key
testkey -- a generic key for packages that do not otherwise specify a key.
platform -- a test key for packages that are part of the core platform.
shared -- a test key for things that are shared in the home/contacts process.
media -- a test key for packages that are part of the media/download system.
2. 制作keystore
- 生成platform.pem
openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform.pem
- 生成platform.p12
openssl pkcs12 -export -in platform.x509.pem -out platform.p12 -inkey platform.pem -password pass:android -name androiddebugkey
- 生成keystore文件
keytool -importkeystore -deststorepass android -destkeystore ./platform.keystore -srckeystore ./platform.p12 -srcstoretype PKCS12 -srcstorepass android
注:有的生成的为platform.jks
,可以直接改为.keystore后缀,不影响使用的。基于以上我们就能够制作出keystore。
androidStudio配置
release {
keyAlias 'platform'
keyPassword 'android'
storeFile file('platform.keystore')
storePassword 'android'
}
另外一种生成keystore的方法(ubuntu系统下)
下载: https://github.com/getfatday/keytool-importkeypair
复制security文件夹中的platform.pk8和platform.x509.pem两个文件
在下载好的文件夹中打开Terminal执行命令: ./keytool-importkeypair -k ./platform.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform
gradle中配置:
signingConfigs{
debug{
try{
storeFile file('../XX.jks')
keyAlias 'XXX'
keyPassword '...'
storePassword '...'
}catch(ex){
throw new InvalidUserDataException("秘钥用户名或密码错误${ex.getMessage()}")
}
}
release{
try{
storeFile file('../XX.keystore')
keyAlias 'XXX'
keyPassword '...'
storePassword '...'
}catch(ex){
throw new InvalidUserDataException("秘钥用户名或密码错误")
}
}
}
buildTypes {
debug{
signingConfig signingConfigs.debug
...
}
release {
signingConfig signingConfigs.release
...
}
}
查看apk的签名信息
1.修改apk后缀名为zip
2.解压缩zip文件
3.进入 压缩文件>META-INF
4.执行命令:keytool -printcert -file XXX.RSA
遇到的问题点:
1. 系统签名之后,安装失败INSTALL_FAILED_SHARED_USER_INCOMPATIBLE [解决办法:clean一下工程就好]
2. 安装之后service启动不起来 []
参考:
https://www.jianshu.com/p/b63afd286a71
https://blog.csdn.net/xk7298/article/details/93332419