本文介绍了如何使用科尔多瓦命令行界面来创建签名的APK文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是第一次从事阿帕奇科尔多瓦。我做了一个示例应用程序的名称的checkStatus 。现在,我想创建签署 APK文件。这样我就可以在我的测试不同的设备上安装。

对于这一点,我瞪大眼睛,发现这个文档

根据文件,我切换到我的项目目录,并运行以下命令。

 的keytool -genkey -v -keystore关键name.keystore -alias别名名-keyalg RSA -keysize 2048 -validity 10000
 

运行上面的命令后,我在 projectRoot /密钥name.keystore得到了一个文件名为键name.keystore

然后我就复制粘贴这个文件到 projectRoot /平台/安卓/关键name.keystore

在这之后,我创建了一个文件名为 ant.properties 并保存在 projectRoot /平台/ Android版

我写了下面code这个文件里面

  key.store = projectRoot /关键name.keystore

key.alias =对myApp
 

在这之后,我跑下面的命令来释放

 科尔多瓦建立机器人--release
 

它抛出下面的错误

  /home/projectRoot/platforms/android/cordova/node_modules/q/q.js:126
                扔ê;
                      ^
错误code 1的命令:蚂蚁ARGS: release,-f,/home/projectRoot/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen

 错误:/家庭/ projectRoot /平台/安卓/科尔多瓦/编译:命令失败,退出code 8
在ChildProcess.whenDone(/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
在ChildProcess.EventEmitter.emit(events.js:98:17)
在maybeClose(child_process.js:753:16)
在Process.ChildProcess._handle.onexit(child_process.js:820:5)
 

所以这一次,我修改 key.store ant.properties 值文件就像下面的方法。

  key.store = /家庭/ projectRoot /平台/安卓/关键name.keystore
 

再次运行科尔多瓦构建Android --release 命令。同样的错误它抛出。

在这里我做错了,谁能帮助我。

感谢。

解决方案

第1步:

  D:\项目\ PhoneGap的\例>科尔多瓦插件RM org.apache.cordova.console
 

步骤2:

要生成一个发布版本为Android,我们首先需要做一个小的变化,以在平台/ Android的发现AndroidManifest.xml文件。编辑文件,并修改该行:

 <应用机器人:可调试=真正的机器人:hardwareAccelerated =真正的机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME&GT ;
 

和改变机器人:可调试为假:

 <应用机器人:可调试=假的Andr​​oid版本:hardwareAccelerated =真正的机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME&GT ;
 

步骤3:

现在我们可以告诉科尔多瓦生成我们的发行版本:

  D:\项目\ PhoneGap的\例>科尔多瓦建设--release机器人
 

然后,我们可以找到我们的平台/安卓/蚂蚁构建签名的APK文件。在我们的例子中,该文件是平台/安卓/蚂蚁建造/举例发布-unsigned.apk

步骤4:

请注意:我们有自己的密钥库keystoreNAME-mobileapps.keystore在这个混帐回购协议,如果你想创建一个,请继续下面的步骤

密钥生成:

语法:

 的keytool -genkey -v -keystore< keystoreName>的.keystore -alias<密钥库aliasname的> -keyalg<密钥算法> -keysize<关键尺寸与GT; -validity<在天&GT键有效;
 

EGS:

 的keytool -genkey -v -keystore名称mobileapps.keystore -alias NAMEmobileapps -keyalg RSA -keysize 2048 -validity 10000


密钥库的密码? :XXXXXXX
什么是您的第一个和最后一个名字吗? :XXXXXX
什么是您的组织单位的名称? :XXXXXXXX
什么是您的组织的名称? :XXXXXXXXX
您所在的城市或区域名称? :XXXXXXX
您所在的州或省的名称? :XXXXX
什么是两个字母的国家code本单位? :XXX
 

那么关键存储已产生与名称作为名称mobileapps.keystore

第五步:

将生成的密钥存储在    D:\项目\ PhoneGap的\实例\平台\机器人\蚂蚁构建

要签署的无符号APK,运行jarsigner工具它也包含在JDK:

语法:

 的jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore< keystorename<未签名的APK文件> <密钥库别名名称>
 

EGS:

  D:\项目\ PhoneGap的\实例\平台\机器人\蚂蚁构建>的jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore名称mobileapps.keystore举例发布,unsigned.apk xxxxxmobileapps

输入的关键词为XXXXXXXX
 

这标志代替APK。

第六步:

最后,我们需要运行的zip对齐工具来优化APK:

  D:\项目\ PhoneGap的\实例\平台\机器人\蚂蚁构建> zipalign -v 4例释放,unsigned.apk Example.apk
 

  D:\项目\ PhoneGap的\实例\平台\机器人\蚂蚁构建> C:\ PhoneGap的\ ADT-束的Windows x86_64-20140624 \ SDK \集结TOOLS \ Android为4.4W \ zipalign -v 4例释放,unsigned.apk Example.apk
 

现在,我们有我们的最终版本的二进制称为example.apk,我们可以释放这对谷歌Play商店。

This is the first time working on apache Cordova. I made a sample application name as checkStatus. Now I want to create signed APK file. so I can install in different devices for my testing.

For this, I Goggled and found this documentation.

As per document, I switch to my project directory and ran the following command.

keytool -genkey -v -keystore key-name.keystore -alias alias-name -keyalg RSA -keysize 2048 -validity 10000

After ran the above command, I got a file name as key-name.keystore at projectRoot/key-name.keystore.

And then I copy pasted that file into projectRoot/platforms/android/key-name.keystore.

After that, I created a file name as ant.properties and saved it in projectRoot/platforms/android

I wrote the following code inside of that file

key.store=projectRoot/key-name.keystore

key.alias=myApp

after that, I ran the following command to release

Cordova builds android --release

It's throwing following error

 /home/projectRoot/platforms/android/cordova/node_modules/q/q.js:126
                throw e;
                      ^
Error code 1 for command: ant with args: release,-f,/home/projectRoot/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen

 Error: /home/projectRoot/platforms/android/cordova/build: Command failed with exit code 8
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)

So this time, I modified key.store value in ant.properties file like in the following way.

 key.store=/home/projectRoot/platforms/android/key-name.keystore

Again ran Cordova build android --release command. the same error it's throwing.

where I did wrong, can anyone help me.

Thanks.

解决方案

Step 1:

D:\projects\Phonegap\Example> cordova plugin rm org.apache.cordova.console

Step 2:

To generate a release build for Android, we first need to make a small change to the AndroidManifest.xml file found in platforms/android. Edit the file and change the line:

<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">

and change android:debuggable to "false":

<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">

Step 3:

Now we can tell cordova to generate our release build:

D:\projects\Phonegap\Example> cordova build --release android

Then, we can find our unsigned APK file in platforms/android/ant-build. In our example, the file was platforms/android/ant-build/Example-release-unsigned.apk

Step 4:

Note : We have our keystore 'keystoreNAME-mobileapps.keystore' in this Git Repo, if you want to create another, please proceed with the following steps.

Key Generation:

Syntax:

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

Then the Key store has been generated with name as NAME-mobileapps.keystore

Step 5:

Place the generated keystore in D:\projects\Phonegap\Example\platforms\android\ant-build

To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

Syntax:

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

Enter KeyPhrase as 'xxxxxxxx'

This signs the apk in place.

Step 6:

Finally, we need to run the zip align tool to optimize the APK:

D:\projects\Phonegap\Example\platforms\android\ant-build> zipalign -v 4 Example-release-unsigned.apk Example.apk

OR

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

Now we have our final release binary called example.apk and we can release this on the Google Play Store.

这篇关于如何使用科尔多瓦命令行界面来创建签名的APK文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:52