Archive for ‘General Development’

January 8, 2013

Installing Apache Cordova/PhoneGap 2.2 for Android development under Windows

I’m dabbling in several projects developing for mobile devices at the moment, and the first thing I’ve had to do is set up the appropriate development environment(s). One such example was to perform a fresh install of PhoneGap (the last version I used was 0.9, the current version is 2.2.0). As there’s an awful lot of outdated/incorrect information on the ‘net that might cause new users confusion about this, I thought I’d jot a few notes on the process here.

Why would you want PhoneGap?

PhoneGap is an open-source framework allowing you to write code using HTML, Javascript and CSS, which it then packages up into Android, Windows Phone, or iPhone/iPad applications (or various others). This is a pretty neat idea for developers who either don’t want to rewrite their applications for each platform or who, like me, are fairly knowledgeable with HTML/JS but don’t know where to begin with Java/Objective-C used to build native mobile applications. In fact, using PhoneGap as a wrapper around the Bing Maps AJAX control is the recommended way to create Bing Maps applications for Android.

#1: “PhoneGap” == “Apache Cordova”

You can read about the history of PhoneGap here. Not that you need to, but it might explain why you’ll end up following links that say “Getting started with PhoneGap” only to be led to a page titled “Apache Cordova Documentation”.

image

As at the time of writing, you can consider these two terms completely equivalent names for the same thing, and you’ll notice them used almost interchangeably throughout the examples and documentation.

#2: “PhoneGap” != “PhoneGap Build”

PhoneGap is a set of templates and files that you install to your local machine and which, in combination with the appropriate development SDK (Android/iOS) allow you to package your HTML/JS code as a native mobile app.

PhoneGap Build is an online packaging service, which means you can upload your HTML/JS/CSS and receive an iOS/Android/Windows app back in return without ever needing the SDK installed on your local computer, but you’ll have to pay to build a commercial app using that service.

Note that you can’t compile an iOS app on a Windows PC (with or without PhoneGap) – you’ll either have to get hold of a Mac, or use the PhoneGap Build service instead. But you can compile for Android (and Windows Phone etc.) on a Windows PC, all from the same codebase, so long as you have the relevant SDK installed.

#3: Pre-Requisites for Installation

The requirements stated on the official PhoneGap/Apache Cordova “Getting Started with Android” page are horribly wrong. What you actually need to develop Android applications via PhoneGap on a PC is as follows:

  • Java (http://www.java.com/en/download/index.jsp). Note that some sources state you need only the Java Runtime Engine (JRE), whereas others state you need the Java Development Kit (JDK – which includes the JRE). Unfortunately, as I already had both installed, I can’t verify which is correct. But you certainly need at least the JRE installed.

image

  • Download and extract the latest PhoneGap/Cordova 2.2.0 zipball. Note that there is nothing to install – PhoneGap is basically just a set of template files and libraries rather than an application.
  • Download and install the Android Developer Tools Bundle for Windows (ADT-bundle) from http://developer.android.com/sdk/index.html.
  • That’s it! You do not need to separately download or install Eclipse, the ADT plugin, ANT, or any other nonsense – these are all included and correctly configured in the ADT bundle already.

#4: The Sample Application does not do what you think it will

It seems natural to start by examining the source code for the supplied PhoneGap sample application (located in lib/android/example/). If you look at the javascript file for that application, in assets/www/main.js, you’ll see lots of useful functions, such as:

var deviceInfo = function() {
    document.getElementById("platform").innerHTML = device.platform;
    document.getElementById("version").innerHTML = device.version;
    document.getElementById("uuid").innerHTML = device.uuid;
    document.getElementById("name").innerHTML = device.name;
    document.getElementById("width").innerHTML = screen.width;
    document.getElementById("height").innerHTML = screen.height;
    document.getElementById("colorDepth").innerHTML = screen.colorDepth;
};


There’s also functions with what sound like fairly descriptive names:

getLocation()
beep()
vibrate()
show_pic()
get_contacts()
toggleCompass()

 

It seems reasonable from looking at these functions to expect that the sample application therefore provides some sort of testing of the device capabilities on which it is running. You might therefore be somewhat surprised to compile and deploy the application only to get this:

image

 

That’s it? Where’s all the device info? Has the application crashed? Is it because I’m running it in an emulator that it can’t access the device capabilities?

Nope - the (slightly bizarre) explanation is that the sample PhoneGap application includes loads of extra code that never ever gets executed. In fact, the only thing that actually gets executed is a splash screen with a green pulsating button saying “device is ready”. How this is meant to be a learning aid is beyond me, but if you get the screen above, then your Cordova installation is working fine – that’s all the sample application does. (It seems I’m not the only one surprised by this – see http://stackoverflow.com/questions/13804533/phonegap-2-2-0-cant-get-past-the-device-is-ready-screen-on-android)

#5 Emulation and Deployment

If the Android emulator crashes, try toggling the GPU acceleration/changing Screen Resolution settings. There are known bugs with certain sizes of emulator on Windows 7 64-bit, especially with GPU acceleration enabled, as reported at http://code.google.com/p/android/issues/detail?id=28515 and http://code.google.com/p/android/issues/detail?id=28601

To deploy the packaged PhoneGap app on an actual Android device over USB, you need to install the appropriate USB driver (not just the one that you use to copy files to/from your device). For the Sony Xperia S handset I use, this can be found at developer.sonymobile.com/downloads/drivers/xperia-s-driver-for-ics/ . You can check that the device is installed correctly by executing "adb devices" from a command prompt in the platform-tools directory.

After all that…

Documentation and stability issues aside, I’m actually pretty impressed with PhoneGap – for non-CPU intensive applications it’s a pretty efficient and easy way to get “native” apps installed on your Android phone which, with a little polishing, would be perfectly suitable to publishing in the Google Play store. Note that performance is not going to be as good as a native app, although exactly how the two compare seems to vary quite a bit from device-to-device.

Certainly, if you’re comfortable with HTML/JS and want to try out a quick prototype of a mobile app, I’d recommend you give PhoneGap a try. There are alternatives (I’m also playing around with CocoonJS), but these tend to be for specific purposes – e.g. HTML5 canvas games – whereas PhoneGap is a more universal tool.

March 8, 2012

Beginning Kinect Programming (again)

A9781430241041-small_1I was pleasantly surprised when, earlier on today, a copy of “Beginning Kinect Programming with the Microsoft Kinect SDK” dropped through my letterbox onto the floor.

I’d first noticed this book was being written a few months ago, when (like everyone else, it seems) there was quite a lot of activity creating various Kinect mash-ups. You’ve probably already seen, for example, videos on YouTube of people controlling Bing Maps or  SQL server using gestures recognised by Kinect. I’d fiddled around with Kinect programming a bit, but then more pressing matters over recent months caused my interest to fall by the wayside somewhat. I’d actually forgotten about this book completely, but I’m hoping that its arrival will prompt me to find some time to look at the SDK again.

I don’t imagine I’m going to come up with anything that will push the boundaries of what’s already been done with the Kinect by others, but I’m hoping that this book will at least teach me how to emulate (i.e. blatantly rip-off) some of the existing Kinect mash-ups. A quick flick-through seems encouraging – I’ll let you know when I find the time to follow through the examples in more detail. (Incidentally, if anybody has any suggestions for a novel natural user interface that I could try to build for a spatial application I’d love to hear it).

Currently, I’m probably thinking about something using the Bing Maps WPF control, but I don’t want to just re-use the common “Minority Report” gestures as in the video above – I’ve got an idea that would require full skeletal-tracking, but I need to think it through a bit more. The other thing I’m wondering about is making use of speech recognition – I don’t know what the capacity of the Kinect dictionary is but could you, for example, load (a subset of) the geonames database to create a speech-navigable map of the world?

Full Disclosure: You don’t get paid much for being an author, but you do benefit from heavily-subsidised rates on your publisher’s other books. I have neither been asked nor paid by APress to mention this book, but I didn’t pay full retail price for it either. There you go.

Tags:
September 14, 2011

Windows 8 Developer Preview

Like, it seems, many people, I’ve spent some portion of today downloading and playing with the first preview version of Windows 8, released in the early hours of this morning. You can grab the release either from the windows dev centre or from MSDN. If you’ve got an MSDN account, I strongly recommend using the latter (together with the download manager) – it gave me download speeds of 25Mbps rather than 0.5Mbps from the public download link.

Once you’ve nabbed the .iso file, you’ll want to install it. If you go for the x64bit version with the developer tools, as I did, the first thing I noticed is that the file is 4.8Gb – too big to burn onto regular DVD media. Not a big deal, as I was planning to install this under a virtual machine on the computer onto which I’d downloaded the ISO anyway, but possibly worth noting.

Scott Hanselman posted a blog article explaining how to boot Windows 8 from a VHD created from this ISO, but the steps involved seemed rather convoluted to me (requiring a USB stick, manual disk partitioning, and lots of disclaimers in case you irreparably break your PC…). What’s more, I’m in the habit of installing any CTP/Beta software under virtual machines that I can run from within my host OS rather than replacing it, so I wasn’t too keen to follow his approach. So I set about creating a virtual machine on which I could run the preview instead.

I normally use VMWare Player as my virtualisation client of choice (not the fastest, but free, reliable, and fairly feature-rich). However, as has been noted by several people on Twitter, the current developer preview release simply doesn’t work in VMWare Player. Trying to create a new Virtual Machine based on the ISO file simply generates the error vcpu-0:NOT_IMPLEMENTED as shown below:

image

I haven’t personally tried it, but I understand that Microsoft Virtual PC suffers from the same problem, so don’t bother going there either.

Fortunately, (and slightly ironically) Oracle’s Virtual Box seems to have more success loading the Windows 8 image than either VMWare’s or Microsoft’s offerings. So, grab a Virtual Box if you haven’t already (why not? It’s free!) and create a new system, using “Other Windows” as the OS type. I don’t know what the minimum required specs are for Windows 8, but I gave the VM 4096Mb of RAM and 60Gb hard drive, which should be plenty. Choose to create a new start-up hard disk using the VDI file format. (More detailed instructions on these steps can be found at http://www.windows7hacker.com/index.php/2011/09/install-windows-8-developer-preview-on-virtualbox/)

Once the machine is created, start it up and on the “installation media” dialog box, navigate to the WindowsDeveloperPreview-64bit-English-Developer.iso image on the host machine. Then finish the wizard and, if all goes well, you should shortly be seeing this:

win8

Note that, if you don’t see the above, but see an error status 0xc0000225 An unexpected error has occurred instead …

image

… then it’s possibly because you haven’t got the APIC setting enabled on the BIOS for your virtual machine. Shutdown the VM, then open the VirtualBox settings and ensure that the checkbox highlighted below is checked:

image

Now try booting the VM up again.

The final question, of course, is that having got Windows 8 to boot, what the heck are going to do with it? I’ve just spent 10 minutes swiping aimlessly around…

Tags:
June 12, 2011

Cloud Hack

I spent a very enjoyable day yesterday in London at The Cloud Hack – a one day coding fest in which developers were invited to combine data from two or more APIs and create a cloud-based app, hosted on Windows Azure, with the chance to win cash prizes.

The event was sponsored by Microsoft, and the APIs made available to the developers for the day included Huddle, Paypal, National Rail Enquiries, and Bing Maps. Prizes were awarded for the best use of these APIs, the best overall app, and the most ambitious app.

I wasn’t competing; rather, I was there to provide technical support for anybody who wanted to use the Bing Maps APIs in their application (which, as it turned out, was almost everyone). I do find it slightly odd that, at a Microsoft-sponsored event designed to promote Windows Azure, Microsoft didn’t supply any of their own technical staff for this role… don’t get me wrong, I had a great time, and it’s always flattering to be recognised as a technical expert in the field, but I found myself standing alongside product managers and technical leads from the other partner APIs as the sole technical contact for the Bing Maps product and also basically providing a sales pitch on their behalf. Microsoft Bing Maps marketing department – I’ll be sending you my bill!

Anyway, there were some pretty good apps came out of it – although (and I’m not surprised) many teams struggled to get all the way from concept design, getting to grips with 5 different APIs, and then deploying to Azure all in a compressed day event. Some ideas included:

  • Combining Bing Maps walking directions with National Rail departure information to determine if you would make it to the train station before your train left
  • A charity event planning website that provided event organisers with event management, donation and payment options, and a map to the venue
  • A holiday planning app that created a personalised itineraryand map of activities to do in a particular location.

One other application that made me smile was “iParcel – a social parcel delivery network”.  Travellers could log on to the site and provide details of a journey they were making by train, using the National Rail API. People who wanted to send a parcel somewhere could also register and say from and to where they’d like to deliver their parcel. Huddle was used to register the details of senders and deliverers and put them in contact with each other. The sender could monitor the progress of the package on a Bing Map, and then pay the deliverer using Paypal. So that’s all 4 APIs used, in a mostly cohesive app, leading this application to win the “most ambitious” prize, even if it didn’t have fully working functionality on the day. Also, I suspect that, if such an anonymous parcel-delivery service were ever publicly released, there might be some interesting concerns to address – “…a social networking site for drugs-runners”…?!

iParcel

Anyway, thanks to all the organisers and attendees – and I look forward to attending the next hack event!

Follow

Get every new post delivered to your Inbox.

Join 53 other followers