Saturday 15 September 2012

android - how to create signed APK file using cordova command line interface -



android - how to create signed APK file using cordova command line interface -

this first time working on apache cordova. made sample application name checkstatus. want create signed apk file. can install in different devices testing.

for this, goggled , found documentation.

as per document, switch project directory , ran next command.

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

after ran above command, got file name key-name.keystore @ projectroot/key-name.keystore.

and re-create pasted file projectroot/platforms/android/key-name.keystore.

after that, created file name ant.properties , saved in projectroot/platforms/android

i wrote next code within of file

key.store=projectroot/key-name.keystore key.alias=myapp

after that, ran next command release

cordova builds android --release

it's throwing next error

/home/projectroot/platforms/android/cordova/node_modules/q/q.js:126 throw e; ^ error code 1 command: ant 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 exit 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)

so time, modified key.store value in ant.properties file in next way.

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

again ran cordova build android --release command. same error it's throwing.

where did wrong, can help me.

thanks.

step 1: d:\projects\phonegap\example> cordova plugin rm org.apache.cordova.console step 2:

to generate release build android, first need create little alter androidmanifest.xml file found in platforms/android. edit file , alter line:

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

and alter android:debuggable "false":

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

now can tell cordova generate our release build:

d:\projects\phonegap\example> cordova build --release android

then, can find our unsigned apk file in platforms/android/ant-build. in our example, file platforms/android/ant-build/example-release-unsigned.apk

step 4:

note : have our keystore 'keystorename-mobileapps.keystore' in git repo, if want create another, please proceed next 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 first , lastly name? : xxxxxx name of organizational unit? : xxxxxxxx name of organization? : xxxxxxxxx name of city or locality? : xxxxxxx name of state or province? : xxxxx two-letter country code unit? : xxx

then key store has been generated name name-mobileapps.keystore

step 5:

place generated keystore in d:\projects\phonegap\example\platforms\android\ant-build

to sign unsigned apk, run jarsigner tool included in 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 come in keyphrase 'xxxxxxxx'

this signs apk in place.

step 6:

finally, need run zip align tool optimize 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 have our final release binary called example.apk , can release on google play store.

android cordova ant

No comments:

Post a Comment