Your own Android application!

Spread the love

This article will help you developing your first Android application based on Adobe AIR.

All tools are free of charge available. This article is assuming you use (Ubuntu) Linux.

Prepare your development environment

First download the software development kits (SDKs):

Unpack these SDKs in the directory:

/opt/android

Add the directories of the SDKs which contains the executables to the environment variable: PATH by executing this command:

export PATH=$PATH:/opt/android/android-sdk-linux_x86/tools:/opt/android/flex_sdk_4.1.0.16076/bin

Creating your application

Now it’s time to create a HelloWorld-application.

  • Create project directory:
    mkdir helloworld

    and step into that directory:

    cd helloworld
  • Create subdirectory: assets
  • Create subdirectory: assets/img
  • Create 3 PNG-images (36×36 pixels, 48×48 pixels and 72×72 pixels) representing the icons of the application.
    Place these 3 files in the directory: assets/img

Create the file HelloWorld.mxml containing these contents:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
 xmlns:fx="http://ns.adobe.com/mxml/2009"
 xmlns:s="library://ns.adobe.com/flex/spark"
 xmlns:mx="library://ns.adobe.com/flex/mx">

 <s:Label text="Hello World" x="27" y="16"/>
</mx:Application>

Now execute

amxmlc HelloWorld.mxml

to compile the HelloWorld.swf file. amxmlc = Adobe Air MXML Compiler.

Create your self-signed certificate by executing the command:

adt -certificate -cn AnythingHere 1024-RSA test_cert.pfx password

Now create the file application.xml which describes your Adobe AIR application:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/2.5">
 <id>net.videgro.HelloWorld</id>
 <filename>HelloWorld</filename>
 <name>HelloWorld</name>
 <versionNumber>1.0</versionNumber>
 <supportedProfiles>mobileDevice</supportedProfiles>
 <android>
 <manifestAdditions>
 <![CDATA[
 <manifest>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.INTERNET" />
 </manifest>
 ]]>
 </manifestAdditions>
 </android>
 <initialWindow>
 <content>HelloWorld.swf</content>
 <visible>true</visible>
 </initialWindow>
 <icon>
 <image36x36>assets/img/icon36.png</image36x36>
 <image48x48>assets/img/icon48.png</image48x48>
 <image72x72>assets/img/icon72.png</image72x72>
 </icon>
</application>

As example the Adobe AIR application asks permission to obtain location information (android.permission.ACCESS_FINE_LOCATION) and use the Internet connection (android.permission.INTERNET). In this HelloWorld-example the AIR application is not actually using one of both.

Hint: You can test the application by executing the AIR Debug Launcher (ADL) :

/opt/android/AdobeAIRSDK/bin/adl application.xml

Next step is to package your application to an APK-file using the AIR Developer Tool (adt). Use this command to create an Android package which you can install at your Android emulator:

/opt/android/AdobeAIRSDK/bin/adt -package -target apk-emulator -storetype pkcs12 -keystore test_cert.pfx -storepass password HelloWorld.apk application.xml HelloWorld.swf assets/img/*

Use the full path to ‘adt’ in the Adobe AIR SDK. The ‘adt’ supplied in the current Flex SDK is not capable to package the apk-emulator target.

Testing the application

Now it is time to run our HelloWorld application. But first we have to set up our emulator environment.

Preparing the Android emulator

  • Start the Android SDK and AVD Manager by executing the command:
    android
  • Click: ‘Available Packages’ in the left frame.
  • Now select ‘SDK Platform Android 2.2, API 8 revision 2.
  • Click ‘Install Selected’, ‘Accept all’ and ‘Install’.
  • A download will start. Take a coffee.

Create a new Virtual Device using the Android SDK and AVD Manager.

  • After installing, click in the left frame: ‘Virtual Devices’.
  • Click at the right side the button: ‘New…’.
  • Type the name for the new emulator i.e.: ‘Android Emulator’.
  • Select Target: ‘Android 2.2 – API Level 8’
  • Type as size: 100 MiB
  • Keep the other settings unchanged.
  • Click: ‘Create AVD’. AVD = Android Virtual Device
  • Quit the ‘Android SDK and AVD Manager’
  • Start your fresh emulator the first time by executing the command:
    emulator @AndroidEmulator &
  • Wait while the emulator boots up Android.

Install the Adobe AIR runtime on the emulator

When you see the home screen of Android in the emulator, you can install the Adobe AIR runtime at the emulator using the Android Debugger (adb).

Execute this command:

adb -e install /opt/android/AdobeAIRSDK/runtimes/air/android/emulator/Runtime.apk

Hint: -e means connect to the only running emulator at this machine.

 

Install your HelloWorld application

Finally you can install the APK containing your HelloWorld application at the Android emulator.

We assume you are still in the ‘helloworld’-project directory which contains the HelloWorld.apk file and the emulator must be running.

Execute this command:

adb -e install HelloWorld.apk

Hint: Next time use:

adb -e install -r HelloWorld.apk

(reinstall application)

Now click in the emulator the button with a matrix of small squares on the surface. You will enter the screen displaying the icons of the installed applications. One of the icons is the one created by you. Below this icon ‘HelloWorld’ is displayed: Click this icon.

Wait while loading and starting your application.

See your application in action!

Further reading

1 comment

Leave a comment