为什么要签名app
- android app那么多,要给app一个唯一身份,有了这个唯一身份才能上传到app商店中
- 升级应用时若包名一致但签名不一致,APP也会安装失败
- 所以正式版app都要签名,还有许多我不知道的原因......
注意
- 打包前先检查你的app id,起一个不会和别人重复的名字.很多人还在使用
io.ionic.starter
,请赶紧改了.一般命名是com.公司英文名称.应用英文名称
制作签名文件(.keystore文件)
- 使用如下命令生成签名文件
keytool -genkey -v -keystore 你起的名字.keystore -alias 你起的别名 -keyalg RSA -validity 10000
生成签名(.keystore)文件的过程
使用签名文件
- 把上一部生成的签名文件复制到app根目录下
- 然后在app根目录下创建一个名字为
release-signing.properties
的文件,这个文件的内容如下
storeFile=E://work_space//jianshu//ionic2_tabs//ionic2_tabs.keystore
keyAlias=ionic2_tabs
storePassword=ionic2_tabs
keyPassword=ionic2_tabs
打包正式版app(release版)
- 把上一部创建的
release-signing.properties
文件复制到./platforms/android
根目录下
找不到
./platforms/android
目录?执行命令cordova platform add android
- 最后执行
ionic cordova build android -release
或ionic cordova build android --prod --release
生成正式版app
真正的上线的版本都要使用--prod参数,这会压缩app,使app体积变小,启动更快.缺点是这个参数打包很慢,我这里大概需要5到10分钟
最后
其实release-signing.properties
和.keystore
文件放到项目根目录是为了方便使用和好写此教程.
网友评论
Installing "com.kit.cordova.amaplocation" for android
Installing "com.kit.cordova.amapnavigation" for android
Failed to install 'com.kit.cordova.amapnavigation': Error: ENOENT: no such file or directory, open 'E:\project\MSPT\platforms\android\AndroidManifest.xml'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.parseElementtreeSync (E:\project\MSPT\platforms\android\cordova\node_modules\cordova-common\src\util\xml-helpers.js:180:27)
at new AndroidManifest (E:\project\MSPT\platforms\android\cordova\lib\AndroidManifest.js:29:20)
at AndroidProject.getPackageName (E:\project\MSPT\platforms\android\cordova\lib\AndroidProject.js:99:12)
at Api.addPlugin (E:\project\MSPT\platforms\android\cordova\Api.js:223:57)
at handleInstall (C:\Users\Steven Song\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:594:10)
at C:\Users\Steven Song\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:357:28
at _fulfilled (C:\Users\Steven Song\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54)
at self.promiseDispatch.done (C:\Users\Steven Song\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30)
(node:2864) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ENOENT: no such file or directory, open 'E:\project\MSPT\platforms\android\AndroidManifest.xml'
(node:2864) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ionic (Ionic CLI) : 3.19.0
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
@IONIC/app-scripts : 3.1.6
Cordova Platforms : android 7.0.0
Ionic Framework : ionic-angular 3.9.2
System:
Node : v8.9.4
npm : 5.5.1
OS : Windows 10
Execution failed for task ':packageRelease'.
> com.android.ide.common.signing.KeytoolException: Failed to read key xiyunapp from store "E:\qqDemo\yunAppDubug\xiyunapp.keystore": No key with alias 'xiyunapp' found in keystore E:\qqDemo\yunAppDubug\xiyunapp.keystore
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':packageRelease'.
> com.android.ide.common.signing.KeytoolException: Failed to read key xiyunapp from store "E:\qqDemo\yunAppDubug\xiyunapp.keystore": No key with alias 'xiyunapp' found in keystore E:\qqDemo\yunAppDubug\xiyunapp.keystore
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[ERROR] An error occurred while running cordova build android --release (exit code 1). 我的报这个错误 = =
你重新生成一个吧,注意你的release-signing.properties中的路径,别名别写错了
* What went wrong:
Execution failed for task ':packageRelease'.
> com.android.ide.common.signing.KeytoolException: Failed to read key xiyunapp from store "E:\qqDemo\yunAppDubug\xiyunapp.keystore": No key with alias 'xiyunapp' found in keystore E:\qqDemo\yunAppDubug\xiyunapp.keystore
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':packageRelease'.
> com.android.ide.common.signing.KeytoolException: Failed to read key xiyunapp from store "E:\qqDemo\yunAppDubug\xiyunapp.keystore": No key with alias 'xiyunapp' found in keystore E:\qqDemo\yunAppDubug\xiyunapp.keystore
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[ERROR] An error occurred while running cordova build android --release (exit code 1).
Execution failed for task ':packageRelease'.
> com.android.ide.common.signing.KeytoolException: Failed to read key xiyunapp from store "E:\qqDemo\yunAppDubug\xiyunapp.keystore": No key with alias 'xiyunapp' found in keystore E:\qqDemo\yunAppDubug\xiyunapp.keystore
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':packageRelease'.
> com.android.ide.common.signing.KeytoolException: Failed to read key xiyunapp from store "E:\qqDemo\yunAppDubug\xiyunapp.keystore": No key with alias 'xiyunapp' found in keystore E:\qqDemo\yunAppDubug\xiyunapp.keystore
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[ERROR] An error occurred while running cordova build android --release (exit code 1).