Archives for January 2011...

(1 results found)

Build Apps for Android using AS3 without a device

Tue Jan 25 07:20:53 2011

Here's a post I've been meaning to write for a while but never got round to it. Let's get right to it.

1. Getting Set Up

First, go here and get yourself the Android SDK. Make sure it's the right one for your OS. I'm currently using 2.2.

Next, if you haven't got it already, scoot over to Adobe and grab the Flex SDK. I'm current using Hero as it gives support for Air 2.5 (a must have).

I placed both SDKs inside /Developer/SDKs/. I'll refer to this folder as DEV/ from now on. After unzipping the SDKs, I renamed the Flex SDK to 'flex_sdk_4.5' and the android-sdk to 'android-sdk'. I refer to them by these names.

Also, I added the paths to my terminal. If you don't know how to do that, you could just cd (change directory) into the folders your files are in or you could use a search engine to look into how to actual add the path, which I recommend. I'm not going to write about it here.

Finally, download the zip file I put together here : HelloAndroid.zip. This file contains all of the files talked about in this tutorial. For those who wish to do it all from scratch, I would advise at least taking a glimpse at the files contained to see what you will be making before hand (in which case you will have to create your own HelloWorld.as and application.xml files as the code for that is not shown on this page).

2. Creating a 'Hello World' to test

First off, a quick hello world in AS3. Inside the zip that can be downloaded above, there is a file called Main.as. This is a simple hello world program. To compile that file, just type DEV/flex_sdk_4.5/bin/amxmlc file-path/Main.as in your terminal window. Note that 'file-path' needs to be the location of the Main.as file containing your hello world code, which is also the location of the output. If you wish to change the location and name of the swf that is output, please refer to the available compiler options here. If all goes well, you should end up with a file call Main.swf

Now, open up terminal if not already open and type DEV/android-sdk/tools/android. In a few moments, the Android SDK and AVD Manager should pop up. This is where we will create a virual device to test hello world on. If you have a real android device, please use Google to look up how to install your hello world on your device. I will not cover it here.

3. Creating your AVD (Android Virtual Device)

In the Android SDK and AVD Manager ("Android Manager" from now on), under Virtual devices, click the 'New' button on the right. In the 'Name' box, choose a name for your device. I just called mine 'Foo'. Set the target as Android 2.2 (or whichever version you wish to use). After that the default settings should be fine, so just click "Create AVD". That's that done, so you can close the Android Manager now.

4. Create the certificate you'll need for testing

To create a self-signed certificate, type the following into a Terminal window:
DEV/flex_sdk_4.5/bin/adt -certificate -cn yourDigitalID 1024-RSA AndroidSigningCert.p12 yourPassword You could give your own id in place of yourDigitalID. It could be anything now though as this is just a test. You can also change the name of the p12 file to be saved and your password. For simplicity's sake, the zip file that you should have downloaded already contains the AndroidSigningCert.p12 created using this command.

5. The Application XML file

The application xml file can be named anything you like, but the data it contains is consistent and provides important information about you application during the build process. For this hello world app, I've included a file in the zip called 'application.xml'. Feel free to take a look at that in your favourite editor and play around with some of the settings to see what happens. Also note that there are a lot more settings than are actually contained in that file. Please look at Adobe's documentation for more details.

6. Create and APK file from your hello world SWF

Open a Terminal window and type the following making sure you input the correct location of each file DEV/flex_sdk_4.5/bin/adt -package -target apk-emulator -storetype pkcs12 -keystore file-path/AndroidSigningCert.p12 Main.apk file-path/application.xml file-path/Main.swf
The compilation is pretty quick and you should end up with a file called Main.apk.

7. Installing the APK onto the AVD

The installation of applications is simple. On the mac, it seems that the installation requires an extra step though. *First drag your .apk file inside the DEV/android-sdk/tools/ *Next, using Terminal, cd into your DEV/android-sdk/ and open your AVD by typing tools/emulator -avd Foo, where Foo is the name you entered when you created your AVD in the Android Manager. (Note* you could just type DEV/android-sdk/tools/emulator -avd Foo).
To actual install the app open a new Terminal window and type DEV/android-sdk/platform-tools/adb install DEV/android-sdk/tools/Main.apk where Main.apk is the name of your .apk file. In may be worth mentioning that I sometimes ran into a problem where even though my AVD was on and working, it was telling me that the device was offline. Sometimes it takes a while for the the device to get up and running properly so just be patient and keep trying (In terminal, you can toggle through previous commands using the up arrow key).

Once the installation has completed, your app should be visible on the emulator device. But wait, there is just one more thing you have to do before it will run. You have to install the Adobe Air runtime app. You can find that in the DEV/flex_sdk_4.5/runtimes/air/android/emulator/ folder. The file is called Runtime.apk. Just drag it to your DEV/android-sdk/tools/ folder and install it using the same command as before: DEV/android-sdk/platform-tools/adb install DEV/android-sdk/tools/Runtime.apk

Once that is installed you should be good to go. Test your hello world.

I know, I know. It's a lot of work to get it going, but I hear Adobe Burrito will include support for quick install to devices with the click of a button. However, I don't actually think it's all that difficult once you get used to it.

Just a quick word on the uninstalling of apps. At present, there is no feature in the simulator to allow you to update apps you install, as far as I'm aware. So every time you want to try a new build of your app out in the emulator, you have to first uninstall it. To do this, click on 'Settings' (same place as apps). Scroll down to and click on 'Applications', then 'Manage applications'. Then simply click on the app name you wish to uninstall and click the 'Uninstall' button. You should be good to install the new build of your app after that.

Now, all that's left is to find good ideas for some real apps. Should be a cinch... yeah right!

Most recent posts

  1. Flashcards Maker - the app the helps you learn in a flash
  2. Convert Font Suitcase to TTF in 3 Easy Steps
  3. Rain or Shine - Weather Forecast Available Now!
  4. Getting around Apple's silly rules for iOS 10
  5. Localising App Names for iOS and Android

Search site:

Apps by Ubacoda.com

Click the app icons to see more info


Archives

Categories