WARNING!!! THIS IS NOT A FULL STEP-BY-STEP TUTORIAL!

I assume that you already know how to compile a swf with Flash Develop, but I’ll try to go over the basic steps as a quick review. There are quite a few steps along the way to get everything working, so since I don’t want to reinvent the wheel with this how-to so I’ll instead direct you to the original sources I followed where it makes sense:

What you need:

Install and configure FlashDevelop if you haven’t already. FlashGamesDojo also has a nice install/configure tutorial.

Create a new “AIR Flex 4 Projector” project from the Project>New Project menu.

At this point you can follow the “Hello World tutorial for Flixel info if you would like. Otherwise create your game/app/whatever. When you’re done compile your app into a .swf file (press F8 or Project>Build Project from the menu).

Okay, now we have a .swf file! Let’s turn it into an Air for Android application:

You need two text files named CreateCertificate.bat and PackageApplication.bat.  If you created an “AIR Flex 4 projector” project to start with these files will be created for you automatically. If you created a different project type you can either create an “AIR Flex 4 projector” project now and move your project file over to the new folder or, create these files manually in the main project directory.  You’ll need to make some changes to get them working with the 2.5 Beta SDK. Here are mine to use as examples, please change the password, application names, and path to SDKs as appropriate:

CreateCertificate.bat:

@echo off

:: AIR certificate generator
:: More information:
:: http://livedocs.adobe.com/flex/3/html/help.html?content=CommandLineTools_5.html#1035959
:: http://livedocs.adobe.com/flex/3/html/distributing_apps_4.html#1037515

:: Path to Flex SDK binaries
set PATH=%PATH%;C:\AIR25_win_sdk\bin

:: Certificate information
set NAME=SelfSigned
set PASSWORD=FD
set CERTIFICATE=SelfSigned.pfx

call adt -certificate -cn %NAME% 1024-RSA %CERTIFICATE% %PASSWORD%
if errorlevel 1 goto failed

echo.
echo Certificate created: %CERTIFICATE%
echo With password: %PASSWORD%
echo.
echo Hint: you may have to wait a few minutes before using this certificate to build your AIR application setup.
echo.
goto end

:failed
echo.
echo Certificate creation FAILED.
echo.
echo Troubleshotting: did you configure the Flex SDK path in this Batch file?
echo.

:end
pause

PackageApplication.bat:

@echo off

:: AIR application packaging
:: More information:
:: http://livedocs.adobe.com/flex/3/html/help.html?content=CommandLineTools_5.html#1035959

:: Path to Flex SDK and ANDROID binaries
set PATH=%PATH%;C:\AIR25_win_sdk\bin
set PATH=%PATH%;C:\android-sdk-windows\tools

:: Signature (see 'CreateCertificate.bat')
set CERTIFICATE=SelfSigned.pfx
set SIGNING_OPTIONS=-storetype pkcs12 -keystore %CERTIFICATE%
if not exist %CERTIFICATE% goto certificate

:: Output AIR
if not exist air md air
set AIR_FILE=air/MyApp.air

:: Output APK
if not exist apk md apk
set APK_FILE=apk/MyApp.apk

:: Input
set APP_XML=application.xml
set FILE_OR_DIR=-C bin .

echo Signing AIR setup using certificate %CERTIFICATE%.
call adt -package %SIGNING_OPTIONS% %AIR_FILE% %APP_XML% %FILE_OR_DIR%
if errorlevel 1 goto failed

echo.
echo AIR setup created: %AIR_FILE%
echo.

echo Signing APK setup using certificate %CERTIFICATE%.
call adt -package -target apk %SIGNING_OPTIONS% %APK_FILE% %APP_XML% %FILE_OR_DIR%
if errorlevel 1 goto failed

echo.
echo APK setup created: %APK_FILE%
echo.

:: APK INSTALL
echo Installing package... %APK_FILE%
call adb install %APK_FILE%
if errorlevel 1 goto failed2

echo.
echo Android setup installed: %APK_FILE%
echo.
goto end

:certificate
echo Certificate not found: %CERTIFICATE%
echo.
echo Troubleshotting:
echo A certificate is required, generate one using 'CreateCertificate.bat'
echo.
goto end

:failed
echo AIR setup creation FAILED.
echo.
echo Troubleshotting:
echo did you configure the Air SDK path in this Batch file?
echo %PATH%
echo.

:failed2
echo Android install FAILED.
echo.

:end
pause

Next, let’s install the Android SDK. Then create a virtual device following the “Create an AVD” part of this tutorial. Fire up the virtual device you just created. This will take a while…

Install the Air Runtime on the Android device by opening a Windows terminal window (Windows Start Menu> type “cmd”) and entering the command:

adb install pathToRuntime/Runtime.apk

Now you’ve compiled your SWF, you have the Android emulator up and running with Air installed on it, all you have to do is right click on CreateCertificate.bat and select “Execute” from the popup menu. This will generate a certificate that can be used to sign your application.

Next,  right click on PackageApplication.bat and select “Execute” from the popup menu. Fill in the password you specified in CreateCertificate.bat file both times when prompted. Two steps happen here: The first one generates an .air file and the second generates an .apk file (and attempts to install it on an attached Android phone or the already running Android emulator).

And that’s it. If you’ve compiled your first Adobe Air for Android application! If you get stuck along the way the “Developing_AIR_Apps_for_Android” pdf included in the Adobe Air for Android SDK is an invaluable resource – just follow the the parts for “command line tools”.

droid_emu

Post to Twitter Twitter Post to Delicious Delicious Post to Digg Digg Post to Facebook Facebook Post to StumbleUpon StumbleUpon