Wednesday, October 15, 2014

Using Adobe AIR Tools to Turn an SWF into a Native Executable

Here's a post to remind myself how to do this.

We have a strange bug in the Windows build of Spacejacked: the game hangs for long periods (usually more than a minute) at random intervals. I suspect it has to do with the audio code in the game, but haven't figured out a way to track it down.

As a temporary workaround, we're packaging the Flash version of the game into a native Windows executable via Adobe AIR.

Steps:

  1. Adobe requires a code-signing certificate for digitally signing your executables. Either follow the instructions on http://help.adobe.com/en_US/air/build/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff0.html and get one from a certification authority, or create your own (if you're just making a test build) like so:
    adt -certificate -cn ADigitalID 1024-RSA SigningCert.p12 39#wnetx3tl
    This creates a .p12 cert named "SigningCert.p12" with common name "ADigitalID" with password "39#wnetx3tl". The full command specification can be found at http://help.adobe.com/en_US/air/build/WS901d38e593cd1bac1e63e3d128fc240122-7ffc.html.
  2. Create an application descriptor XML file, as mentioned in http://help.adobe.com/en_US/air/build/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff1.html.
    For example, here's our spacejacked.xml:
    <?xml version="1.0" encoding="utf-8" ?>
    <application xmlns="http://ns.adobe.com/air/application/3.2">
        <id>com.rottenmage.spacejacked</id>
        <versionNumber>0.0.1</versionNumber>
        <filename>SPACEJACKED</filename>
        <name>Spacejacked</name>
         <description>
            <text xml:lang="en">SPACEJACKED</text>
        </description>
        <copyright>Copyright (c) 2014 Rotten Mage Pte Ltd</copyright>
        <initialWindow>
            <title>SPACEJACKED</title>
            <content>
                SPACEJACKED.swf
            </content>
            <visible>true</visible>
            <resizable>false</resizable>
            <maximizable>false</maximizable>
            <renderMode>direct</renderMode>
        </initialWindow>
        <icon>
            <image16x16>icons/smallIcon.png</image16x16>
            <image32x32>icons/mediumIcon.png</image32x32>
            <image48x48>icons/bigIcon.png</image48x48>
            <image128x128>icons/biggerIcon.png</image128x128>
        </icon>
        <supportedProfiles>desktop extendedDesktop</supportedProfiles>
    </application>
    
    where SPACEJACKED.swf is the name of the SWF file we are wrapping. Note that the namespace specified in xmlns in the <application> tag should be set to an appropriate version that corresponds to the SWF version you are targeting; details at http://help.adobe.com/en_US/air/extensions/WSf268776665d7970d-2e74ffb4130044f3619-8000.html.
  3. Create a directory structure for packaging (details at http://help.adobe.com/en_US/air/build/WS901d38e593cd1bac1e63e3d128cdca935b-8000.html). For a quick-and-dirty solution, we use:
    /SPACEJACKED
        SPACEJACKED.swf
        spacejacked.xml 
    with the certificate just outside of this structure.
  4. Finally, from within the root of the packaging directory, run in the command prompt (for a Windows build):
    adt -package -storetype pkcs12 -keystore ..\SigningCert.p12 -target bundle ..\SPACEJACKED_game spacejacked.xml SPACEJACKED.swf
    which will prompt for the certificate's password (created in step 1). This creates the executable in a directory called SPACEJACKED_game one level above the packaging directory.
That should be it. The instructions are similar for other platforms. Note that (as of writing) native bundles/builds can only be created on the same platform, i.e. Windows bundles can only be created on Windows, Mac .app bundles on Mac OS X, Linux .deb/.rpm on the appropriate Linux distros.