Developing Android Applications with Adobe AIR [12]
Reading the logs is a great way to learn about the Android OS, which components are involved, and how various requests are managed.
Type the following at the command line:
androidSDK/platform-tools/adb logcat
If you have the emulator on and the device connected, you can choose the debugging destination:
androidSDK/platform-tools/adb -e logcat
androidSDK/platform-tools/adb -d logcat
You should now see traces along with native messages. If you use the example from Chapter 2, click the button to send email, send text, or make a phone call to see the trace messages.
Android provides a message filtering system using priority levels from Verbose to Silent. To print messages for the running AIR application alone at all levels of priority, use the following command (replace applicationID with your application name as defined in the application descriptor):
adb logcat air.applicationID:V *:S
To print messages from the currently running AIR application as well as the Activity Manager, use the following:
adb logcat air.applicationID:V ActivityManager:| *:S
I prefer a simpler approach to only display trace statements and AS error messages. I restrict logcat to only print messages with the string I.air, as in this command:
androidSDK/platform-tools/adb logcat|grep "I.air"
or this command:
androidSDK/platform-tools/adb logcat|grep "hello" application name
During the packaging process, each AIR application has the word air added to its applicationID. Therefore, using the filter I.air guarantees to dump all messages for the currently running AIR application. I stands for the Information priority level. This level does not display native errors but does display AS error messages.
To clear your Terminal window, on the Mac select Terminal→View→Clear Scrollback. On Windows, type C:\>cls at the command prompt.
Before starting a new debug process, clear the logcat buffer:
androidSDK/platform-tools/adb logcat -c
Accessing the device’s filesystem
The Android ADB gives access to some of the device’s filesystem. Try this command to display all the applications installed on the device:
androidSDK/platform-tools/adb shell pm list packages
Using the Virtual Device Manager and Emulator
If you do not have an Android device, use the Runtime emulator to simulate one and test your application. Keep in mind that the Runtime emulator is very slow for both AIR and Android applications, so you should not consider its performance to be an accurate benchmark of how applications will perform on actual devices. The Runtime emulator is located at AIRSDK→Runtimes→AIR→Android→Emulator→Runtime.apk.
First, compile your application for the emulator:
androidSDK/bin/adt -package -target apk-debug -storetype pkcs12
-keystore yourCertificate.p12 hello.apk Main-app.xml Main.swf
Install the emulator version of the AIR runtime on the emulator:
androidSDK/platform-tools/adb -e install AIR-sdk-path/RuntimeEmulator.apk
A successful installation displays a message similar to this one:
1713 KB/s (6617672 bytes in 3.771s)
pkg: /data/local/tmp/Runtime_Emulator.apk
Success
Install the Android Package (APK) file using -e, for emulator, as a destination:
androidSDK/platform-tools/adb -e install hello.apk
Launch the AVD Manager application: on the Mac, select Android SDK→Tools→Android; on Windows, select Android SDK→SDK Setup.exe.
Create an Android Virtual Device (AVD), an emulator, using the AVD Manager application. Select the Virtual Devices option and click New. Give the device a name and select the target API: Android 2.2, API level 8 (if you don’t see that option, you need to install the API; go back to Chapter 2 for instructions). The size of the SD card and Skin is optional. Click Create AVD.
Click Start to launch the emulator. The virtual device has a panel on the left representing the face of your device, a group of buttons for all input on the top right, and a keyboard on the bottom right.