Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Sunday, 1 December 2013

Script your build and deployment of android cordova apps with powershell

We are developing a new version of our customer facing solution, across web, ios and android, using cordova(phonegap).

Im a big proponent of build automation, and the classical (recommended?) way of using eclipse to build and manage the code base was getting me down, so i decided to write some scripts to build and deploy the app to either a device, an emulator or prepare for release. I also wanted any developer to be able to checkout the code and run the scripts to build the app.

I wrote the scripts in powershell (sorry!) with some batch files to make the various functions easy to run (im developing on windows 8 by the way).

You can find the scripts here: https://github.com/DamianStanger/AndroidBuildScripts

So how does it all work?

firstly it goes with out saying that you need your dev env set up for android development on the command line with cordova http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-Line%20Interface

As you will know (if you do cordova development) when you use the command line tools for creating cordova apps the folder created is where all your source code is placed and inside there is the www folder that is where you keep your .js and .html files. The problem is that you are keeping your source code along side the automatically built cordova files, not ideal. so I've created my own source folder that is where all the code you edit is kept. We then use powershell to copy these files to the correct places.

The development process

In a powershell (or dos cmd if you prefer)

build.bat
emulate.bat or install.bat

Line 01. run either or, depending on if you are using a real device or not

That's it. Now you might notice that build can take a wile to run because its setting up everything from scratch so i created a shortcut that will only copy your changes across.

quickCopy.bat
emulate.bat or install.bat

This is all good for general day to day dev but eventually you will want to test a production build on a real device for this use the following commands

release.bat
installRelease.bat

To make this work you must only have either a device plugged into usb or an emulator turned on (please use genymotion its so much faster than a standard emulator)
The release process signs and aligns your apk for you :-) so when you are ready you just send the apk you have tested to the play store.

The scripts

Here I'm going to show select lines of code from build.ps1

For building the app in debug and getting that on to your emulator or phone

function create()
cordova create app-cordova-android com.myapp.app myapp
...
cordova platform add android
...
cordova plugin add org.apache.cordova.device

function build()
cordova build android
function emulate()
cordova emulate android -d
function installDebug()
cordova run android -d

To build the releaseable apk and to get that onto your phone use the following:

function release()
cordova build android --release
function sign()
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ..\appstore\android-keystore\myapp -keypass myappKeyPassword -storepass myappStorePassword -signedjar .\platforms\android\bin\myapp-release-signed.apk .\platforms\android\bin\myapp-release-unsigned.apk myapp
zipalign -f -v 4 .\platforms\android\bin\myapp-release-signed.apk .\platforms\android\bin\myapp-release-signed-aligned.apk
function installRelease()
adb uninstall com.myapp.app
adb install .\appstore\APKs\myapp-release-signed-aligned.apk

Release versioning

When doing a release to the play store you need to make sure the version numbers are incremented each time, for this i added a helper which will update all the relevent places in the source for you.

just run:

setVersion 102 1.0.2

This will change all the files that need changing in order to properly put a new version of the app onto the play store.

Upload to play store error
Upload failed
You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play

Make sure your manifest is set thus:

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

Resources

Sunday, 17 November 2013

Debug your android applications by capturing/monitoring their http traffic using wireshark

I’ve always wondered what my phone is telling the outside world and recently i had the need to actually find out as I’m developing an android app for work at the moment. I needed to find out what was going over the wire as i was getting some strange problems and could not debug the traffic on the production server.

Setup

Download and install wireshark : https://wireshark.org/

Disable wifi and mobile data on the phone.

Connect your phone to your laptop/desktop via USB.

Enable internet pass though. Basically you want your phones internet to come through the USB wire, through your computer network card, which when running a wireshark capture, through wireshark.

Set up a capture filter so that you only capture the data coming to and from your phone and not data initiated from the computer itself. i pick the option to ‘create a capture with detailed options’. Set a capture filter for example ‘host 192.168.15.129’,  where 192.168.15.129 is the ip address of the phone.

Additionally (or alternatively) you can filter the traffic by ip address after capture when viewing the results “ip.src==192.168.15.129 or ip.dst==192.168.15.129” where 192.168.15.129 is the ip address of your phone. Or filter the traffic by protocol, you probably care about http traffic so filter on this by entering “http” in the filter.

Results

You can get information overload with wireshark, it takes some getting used to, but if you dig you can find everything you need. Look for the requests you care about by looking down the info column and clicking the row. This will present all the packet details where you can dig as deep as you like into the request.

I use the Hypertext Transfer Protocol section as its the level of detail i care about. From here you can see the url and the headers as well as a link to the packet that contains the response, simply perfect.

Sunday, 20 October 2013

HTC One and Vodafone. Removing the Kikin search service

If your like me then you will hate how the phone manufacturers install all sorts of things on your phone for you, (to be fair I think its Vodafone not HTC), and I know its not as bad as the galaxy (I’ve several friends with Samsung phones) but recently my phone started popping up a search service every time I selected (long pressed) a word to copy and paste it. really really annoying.

Anyway the Kikin service (http://www.kikin.com/) was really winding me up, software i didn’t ask for, didn’t want, couldn’t remove but did get in the way every time I wanted to simply select a piece of text.

So how to remove the kikin service?

OK first the bad news, you cant, well not without rooting your phone. But you can disable it so it no longer bothers you by popping up all the time.

Settings -> Apps -> All -> Kikin

Sadly you will see no uninstall, but if you turn notifications off, force stop, then Disable. you are done :-) now the long press select text click doesn't also do a web search automatically.
And I’m not sure but since I’ve done it I have not had Kikin auto update on me, or it might just be happening behind the scenes.

Vodafone, HTC, et al. Please please stop installing useless guff on to our phones. just because you can doesn’t mean you should.

Thursday, 6 January 2011

LauncherPro has expired. 403 forbidden. Phone is locked out...

Ive been using LauncherPro for a couple of months now, its a nice homescreen replacement on the android phone, actually i really liked it.

But this morning when i turned my phone on i got the error :-

"This version of LauncherPro has expired. Please goto http://www.launcherpro.com/ to get the latest version."

Then my web browser automatically opened so i could get it but i had a problem, i had no internet connection, no wifi, and no mobile connection.... arg.. Basically my phone was now a brick, well i could receive calls, but there was no way to access anything else as every time i hit the home key it would redirect to the internet...

Then later on in the morning i went into london and got a connection on 3G but then i got a 403 forbidden page.... double arg, whats going on this is so shoddy, so i still cant use my phone.

Only after getting to a PC with a decent internet connection did i managed to find a couple of solutions, the first was to download an app installer onto the pc and do a remote install of the new version of launcherPro, i didnt like this, it sounded too complex and i wanted rid of it not the latest version.

Then i found the following solution
browse to - http://bubiloop.com/download/org.adw.launcher
this should open the market (app store)
then search for launcherPro and finally update or uninstall.

I recommend un-installing, seams like this is a rather shoddy product if it locks out your phone like this. even if the actual software does everything else well i dont think this sort of error is in any way acceptabe in any software ever, locking you out of your device, laptop, PC whatever it is, is just wrong, i appreciate the developers might want to force people to upgrade all the time, but this is just not on, i dont know i just cant warn you folks enough, i woudnt trust this app.

morel of the story, dont use apps from random developers on major bits of your device, the home screen is quite major, if that dont work your stuffed.

Wednesday, 3 November 2010

Android, how easy is it to deploy or install your own app to your phone

The answer is very easy

So you have spent a few hours developing a new android app (ive been using the eclipse IDE) and you have been testing using the adb emulator, but you want to see something on your very own android hardware (ive got a HTC Desire).

These are the steps ive followed:
  1. Build your .apk package.
  2. Connect your phone to your pc in disk drive mode (this enables you to mount it on your pc).
  3. Browse to your removable disk (this shows up as drive G: on my machine).
  4. Copy the .apk file that was generated by the build to your phone and remember where you copied it to.
  5. Disconnect the phone.
  6. On the phone use a file manager app like 'ES File Explorer' or 'ASTRO File Manager' and browse to the .apk file you copied on in step 4.
  7. Open the .apk file and select install.
It really is that easy, none of that iphone certificate nonsense, or limited use to tolerate, lets just do it :-)

Setting the date on Android emulator adb

To set the date on your android emulator use the following command from the terminal

adb shell date -s 20101023.130155

This sets the date to be Oct 23rd 13:01:55 2010
easy

Tuesday, 17 August 2010

Vodafone, HTC Desire fiasco

So I've had a contract with Vodafone for over 3 months now. I think it was early may that I actually signed up for a contract with them and got my shiny new HTC Desire, I was pleased. Very pleased :-)

But after a day or 2 I found it was broken :-( if you used it for any length of time it would just quit, turn off, then not turn on for a while whilst it cooled down, oh and there was the strange squeeze thing I mentioned in another blog post.

I complained only 2 or 3 days after I received the original, I thought it would be straight forward, new for new, but unfortunately no stock, the desire is very desirable and there were supply problems.

So I waited and waited, I rang back twice a week to check on progress, I was not using my desire at this point as it was unusable, switching itself off randomly. Back to my trusty old nokia (7 years and still going strong)

And I waited.
Finally, finally after ringing twice a week for 2 months i got a replacement phone :-) yay at last, but I was told to keep my batery, sim and memory card from my other phone, strange, oh well, got my new phone now. :-)

But no, still broken, still with exactly the same problems as before.... ARRRRG, it was the battery all this time, i told them i thought it was, dam it.

And wait what's this, there is as small scuff mark on the base of the phone, its brand new isn't it?

So rang Vodafone back and said it still doesn't work, and also is this phone I have new? there is a scuff mark on it? after much a to-do I got the answer that its a reconditioned phone, and we will send you a battery (which they did but I suspect its not a new one as it came in a jiffy bag).

Anyway after some challenging discussions I got agreement that it was an error to send me a reconditioned phone, apparently an error in the system (problems with phones over 1 month into the contract get refurbished replacements), since I was 2 months into my contract I get a reconditioned one... even though id reported the problem on day 3... But the supervisor on the other end was reasonable in the end and agreed I should have had a new phone sent not a reconditioned one, and so I'm waiting, again.

And waiting and waiting, I ring back twice a week again, try to get a date but again they are out of stock, out of stock, out of stock.
Do Vodafone ever sell the HTC Desire? I know its a popular phone, that there are supply problems but in effect its been over 3 months now, you cant tell me you have not had any stock in 3 months? really?

I suspect its far more profitable to sell that new handset to a new customer than to sort out your existing ones?

I'm a bit disappointed really, as you can imagine, cause I've been using Vodafone for all my mobile life, years and years, even whilst abroad, and always had excellent service. I've had friends with orange who had trouble and problems with the provider and I've always said come to Vodafone, they are great, but seams like things change, or just maybe I've just got really unlucky.

Thursday, 13 May 2010

HTC Desire shut down problems

So ive got a brand new HTC Desire, and instantly loved it, but its not right...


If you talk on the phone for 5-10 minutes the phone will just switch off? if you use the internet or any other functionality the phone will soon enough just switch off. sometimes if you just gently squeeze it will just shut down.


Once it has shut down the status light flashes green and orange, sometimes it wont even shitch back on for ages...


So ive got in touch with vodafone, and they have been really good about sorting it out. they have quickly agreed to replace it :-) but there are none in stock at the moment, and none due in till the 23rd i think... boo


video of the squeeze



As you can see it works pretty well, quick navigation, just dont squeeze it.