October 13, 2016

building phonegap app for Android and iOS

So I had the pleasure of figuring out how to successfully build and publish a phonegap app, both to the Play store and Apple store. It was bad enough that I have no experience with phonegap/Cordova (or anything iOS development related), but the previous developer had left no documentation. That was fun. Here are some notes of things I ran into along the way. Hope they help someone else out too

So I had downloaded the repo, installed all the dependacies, but now I was getting this error

ERROR in ./src/routes/index.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ./searchByKeyword in /home/george/Documents/work/repositories/ita-app/src/routes

Spent some time looking at Google, when I came across this suggestion to use webpack to display more verbose errors webpack --display-error-details. Genius.

This gave some more verbose output and told me that it was searching for the file, but could not find it in some directories, this helped me realise it was case sensative. The file it was looking for had a capital S, but it was looking for lower case s. Changing the name of the file to lowercase and rebuild

And another error, but on index.jsx file this time. Not sure why it only errored on these 2 files, probably something in the config files but I didn’t rally want to be looking through config files all day (there were alot!) Do the same and rename to lower. And now we get a successful build! Yay!

The previous dev had done this on OSX but not sure why this was an issue on Linux(can understand if it was done on windows, for example)

So now we have an Android apk, but to upload it to the store it needs to be signed (and later on it told me it also has to be zipaligned)

Here is how to do that with command line

#Sign the app with jarsigner (should have been installed along with android studio)
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /home/george/Documents/repositories/myapp/key/myapp.keystore android-x86-release-unsigned.apk myapp

Uh oh, another error

jarsigner: Certificate chain not found for: myapp.  myapp must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain.

Turns out you have to specify the exact alias that is found inside the keystore with the jarsigner command. To get that, run

keytool -keystore /home/george/Documents/repositories/myapp/key/myapp.keystore -l

That will display something similar to this, where you can see the alias name. Now re run jarsigner with the correct alias and you will have a great time

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

Alias name: myapp-release

Now we have a signed apk, but on uplaoding to the store, it errors and tells me its not zip aligned. Luckily this one was easy. /home/george/Android/Sdk/build-tools/24.0.3/zipalign -v 4 android-x86-release-signed.apk android-release-signed-aligned.apk

NOTE only zip align after you have signed

Android down, iOS to go!