Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center /

Updating Adobe AIR applications packaged with a native installer

by Piotr Walczyszyn

Piotr Walczyszyn
  • http://riaspace.com

Content

  • Downloading the update descriptor file
  • Downloading the update file
  • Installing the update file
  • Updating on the Mac OS X platform
  • Where to go from here

Created

28 February 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR deployment distribution open source

Requirements

Prerequisite knowledge

Basic knowledge of ActionScript 3 and MXML.

 

Additional requirements

  • Adobe AIR SDK
  • NativeApplicationUpdater library

User level

Intermediate

Required products

  • Flash Builder (Download trial)
  • Flex 4.1 SDK
  • Adobe AIR

Sample files

  • NativeUpdater.zip

With the release of Adobe AIR SDK 2 developers have the ability to package their applications into native installer files. Later these installer files can be launched on different platforms like Windows (EXE), Mac OS X (DMG) and Linux distributions capable of installing from deb or rpm files. This feature can be useful in various scenarios but its main purpose is the introduction of the NativeProcess API that gives developers the ability to execute native code from AIR applications. This new AIR application installation process ensures that the application will run properly on the targeted platform.

Unfortunately the Update Framework that comes with the AIR SDK doesn't support updates of AIR apps packaged into native installers. The good news is that the NativeProcess API makes it easy to help build your own update mechanism.

This article will step you through the process of how to build your own custom update mechanism for the Windows platform. The logic of this mechanism will be encapsulated in the NativeUpdater class with a single public function updateApplication used to trigger the update process. Download the sample files that accompany this article for the complete source code. For details on how to use the update installer on the Mac OS X platform, refer to the section at the end of this article.

Downloading the update descriptor file

The first step that the update mechanism has to do is to download the update descriptor file to check whether an update is available. The update descriptor file can be the same file you would use with the standard AIR Update Framework. The assumption here is that the application will be built with the AIR 2.5 SDK, which includes the new namespace tag <versionNumber /> (previously <version /> ); this applies to both update descriptor and application descriptor files. The update descriptor file that you can use should look similar to the following:

<?xml version="1.0" encoding="utf-8"?> <update xmlns="http://ns.adobe.com/air/framework/update/description/2.5"> <versionNumber>0.9.1</versionNumber> <url>app:/remoteFolder/NativeUpdater.exe</url> <description>This is a new version of NativeUpdater application.</description> </update>

Note here that the url tag should point to the application directory where your native installer will be placed (most likely somewhere on your http server).

Implementing the downloadUpdateDescriptor function

The downloadUpdateDescriptor function will use the URLLoader class in order to initiate the download process. URLLoader instance will have two event handlers defined to handle complete and IO error events.

protected function downloadUpdateDescriptor():void { var updateDescLoader:URLLoader = new URLLoader; updateDescLoader.addEventListener(Event.COMPLETE, updateDescLoader_completeHandler); updateDescLoader.addEventListener(IOErrorEvent.IO_ERROR, updateDescLoader_ioErrorHandler); updateDescLoader.load(new URLRequest(UPDATE_DESCRIPTOR_URL)); }

Next, the updateDescLoader_completeHandler function reads the downloaded update descriptor XML file and compares the current application version with update version. If those values don't match it invokes the downloadUpdate function passing it the URL address of the native installer file.

protected function updateDescLoader_completeHandler(event:Event):void { var loader:URLLoader = URLLoader(event.currentTarget); // Closing update descriptor loader closeUpdateDescLoader(loader); // Getting update descriptor XML from loaded data var updateDescriptor:XML = XML(loader.data); // Getting default namespace of update descriptor var udns:Namespace = updateDescriptor.namespace(); // Getting application descriptor XML var applicationDescriptor:XML = NativeApplication.nativeApplication.applicationDescriptor; // Getting default namespace of application descriptor var adns:Namespace = applicationDescriptor.namespace(); // Getting versionNumber from update descriptor var updateVersion:String = updateDescriptor.udns::versionNumber.toString(); // Getting versionNumber from application descriptor var currentVersion:String = applicationDescriptor.adns::versionNumber.toString(); // Comparing current version with update version if (currentVersion != updateVersion) { // Getting update url var updateUrl:String = updateDescriptor.udns::url.toString(); // Downloading update file downloadUpdate(updateUrl); } }

Downloading the update file

In this step the update mechanism has to download the update file from the remote location. Before it can start downloading the file it also has to resolve the name of the downloaded file. This is done by parsing out the last fragment of the URL address and creating a reference to the file with the name of that fragment in the temporary directory.

Now to do the actual download procedure; you can use the URLStream class, which is very efficient in this type of scenarios. You could also use URLLoader, but it would buffer the entire application file in memory before it could write it to the hard drive which is not best practice in the case of large application packages.

protected function downloadUpdate(updateUrl:String):void { // Parsing file name out of the download url var fileName:String = updateUrl.substr(updateUrl.lastIndexOf("/") + 1); // Creating new file ref in temp directory updateFile = File.createTempDirectory().resolvePath(fileName); // Using URLStream to download update file urlStream = new URLStream; urlStream.addEventListener(Event.OPEN, urlStream_openHandler); urlStream.addEventListener(ProgressEvent.PROGRESS, urlStream_progressHandler); urlStream.addEventListener(Event.COMPLETE, urlStream_completeHandler); urlStream.addEventListener(IOErrorEvent.IO_ERROR, urlStream_ioErrorHandler); urlStream.load(new URLRequest(updateUrl)); }

Instantiating FileStream

When URLStream is opened, the urlStream_openHandler function is called. Within this function an instance of the FileStream class can get created; this class will be used to write downloaded bytes into the local update file.

protected function urlStream_openHandler(event:Event):void { // Creating new FileStream to write downloaded bytes into fileStream = new FileStream; fileStream.open(updateFile, FileMode.WRITE); }

Writing downloaded bytes into the update file

Update file bytes are downloaded in batches, that is why the progress event has to be handled in order to write those bytes to the local file. The urlStream_progressHandler function is responsible for doing this and it uses ByteArray to read loaded bytes from URLStream and to write these into the FileStream instance.

protected function urlStream_progressHandler(event:ProgressEvent):void { // ByteArray with loaded bytes var loadedBytes:ByteArray = new ByteArray; // Reading loaded bytes urlStream.readBytes(loadedBytes); // Writing loaded bytes into the FileStream fileStream.writeBytes(loadedBytes); }

When URLStream completes downloading update file bytes, both URLStream and FileStream should be closed. Next, the installUpdate function can be called.

protected function urlStream_completeHandler(event:Event):void { // Closing URLStream and FileStream closeStreams(); // Installing update installUpdate(); }

Installing the update file

The last step to be accomplished is actually running the downloaded update file. In order to do this you can use the NativeProcess API. Remember that in order to use this new API your application descriptor (*-app.xml) file needs to set supportedProfiles tag to extendedDesktop value as in the following snippet:

<supportedProfiles>extendedDesktop</supportedProfiles>

Implementing installUpdate function

First, the installUpdate function creates an instance of the NativeProcessStartupInfo class and sets the executable property to the reference of the update file. Next, it uses the NativeProcess class to execute the downloaded update file. At last the application can be closed in order to let the installer run.

protected function installUpdate():void { // Running the installer using NativeProcess API var info:NativeProcessStartupInfo = new NativeProcessStartupInfo; info.executable = updateFile; var process:NativeProcess = new NativeProcess; process.start(info); // Exit application for the installer to be able to proceed NativeApplication.nativeApplication.exit(); }

When the application exits and the update file is launched, users should see the standard update window displayed by the AIR runtime (see Figure 1). Clicking the Replace button initiates the update process; when finished, the application will automatically relaunch.

The AIR Runtime application update window.
Figure 1. The AIR Runtime application update window.

Updating on the Mac OS X platform

In the case of Mac OS X, the process is a bit more complex. First you have to mount the downloaded DMG file. This can be done using the command line util application, hdiutil, which is usually located in /usr/bin/hdiutil. Hdiutil should be executed using the NativeProcess API and have three arguments passed: attach, -plist, and the path to downloaded update file. In return hdiutil will pass the plist XML content which can be read with the  ProgressEvent.STANDARD_OUTPUT_DATA event handler. From the returned XML data you can extract the path to the mounted DMG file, that is passed as value of the mount-point key node. The last step is to execute the installer file that is located in the Contents/MacOS directory of the mounted DMG file. Next the installer can be executed in the same way as on the Windows platform using the NativeProcess API as described above.

Where to go from here

Another option that is available when updating applications packaged with the native installer is to use my NativeApplicationUpdater library, which is available on Google Code. The benefit of using this library is that it hides the differences between the OSes. You can find a short tutorial on how to build custom UI for this library on my blog. You can also watch the following video to see how it works:

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

If you want to build your own updater and also support other OSes I encourage you to look through the NativeApplicationUpdater source code to understand how those other platforms should be handled.

More Like This

  • What's new in Adobe AIR 3
  • Installation and deployment options in Adobe AIR 3
  • Developing cross-platform Adobe AIR applications
  • 10 common mistakes when building Adobe AIR applications
  • Tips for building AIR applications that can be easily updated
  • Adobe AIR and the experience brand
  • Uploading images from CameraRoll and CameraUI
  • Getting started with Adobe AIR for Flex and ActionScript 3 developers
  • Ten tips for building better Adobe AIR applications
  • Deploying Adobe AIR applications seamlessly with badge install

Tutorials and samples

Tutorials

  • Using the iOS Simulator to test and debug AIR applications
  • Using the Amazon In-App Purchase Adobe AIR native extension for Android and Kindle Fire
  • Transferring data with AIR native extensions for iOS – Part 3
  • Exchanging Vector and Array objects between ActionScript 3 and C, C++, or Objective-C

Samples

  • Licensing Adobe AIR applications on Android
  • Using web fonts with Adobe AIR 2.5
  • Using Badger for Adobe AIR applications

AIR blogs

More
07/09/2012 Protected: Publishing Adobe AIR 3.0 for TV on Reference Devices
07/08/2012 Source Code: Adobe AIR 3.3 Retina Video Application
07/06/2012 Application specific File Storage on Adobe AIR based ios Application
07/04/2012 Recent Work - iPad/Android App: Inside My toyota

AIR Cookbooks

More
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay
01/20/2012 Skinnable Transform Tool
01/18/2012 Recording webcam video & audio in a flv file on local drive
12/12/2011 Date calculations using 'out-of-the-box' functions

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement