Emulating a Device
So that you can rapidly test your application from within the IDE, MoSync includes an emulator called the MoSync Runtime Environment (MoRE). MoRE can emulate any device in MoSync's device profile database. The device profile information provides all the configuration settings it needs. You can also install the native Android Emulator and iPhone/iOS Simulator and run your application in those too -- useful if you are working with OpenGL ES, NativeUI, or other APIs that are only available for Android or iOS.
Available Emulators
All MoSync releases:
- The MoSync MoRE emulator is a virtual machine that directly executes MoSync bytecode. It's not just a compilant MoSync implementation - it's the actual reference implementation that all the real device platforms are required to conform to. It is the default emulator in the IDE.
From MoSync 2.6:
The Android Emulator and iPhone/iOS Simulator can be installed and specified as the target emulator for Android or iOS applications so that you can test OpenGL ES, NativeUI Library, and Widget API-based applications. Once installed you just need to select an Android or iOS device profile before you run your application in the IDE. The appropriate native emulator will start up authomatically. For installation instructions, see Installing and Working with Native Emulators.
Starting the MoSync Emulator
To start the MoSync MoRE emulator, click the
Run button on the toolbar (or press Ctrl+F11). The current project is be saved, built using the "Release" build configuration, and loaded into the emulator. A graphical phone is displayed.
(You can also start the emulator in debug mode by clicking the
Debug button on the toolbar. In this case the current project is built using the "Debug" build configuration, before being loaded into the emulator.)
Controlling the MoSync Emulator
The emulator is controlled either by clicking the keys on the graphical phone, or using a number of keyboard shortcuts:

The emulator communicates with the MoSync IDE, sending call stacks, panics, and other useful data to the console window.
Screen orientation
The F4 key on the keyboard toggles the screen orientation of the emulator between portrait and landscape modes (and causes an EVENT_TYPE_SCREEN_CHANGED to be sent to the application).
Multitouch emulation
MoSync 2.5+
Right-click with the mouse pointer on the emulator screen to engage multitouch simulation. Two filled circles appear, equidistant and opposite from the screen's centre point:

To emulate pinch-in, pinch-out, and rotational guestures, move the pointer in different directions while holding down the right mouse button.
Closing the emulator
The Esc key closes the emulator.
The Emulator Device Profile
When it executes a MoSync application, the emulator uses the current device profile. For instance, the screen dimensions of the graphical phone varies according to settings in the current device profile.
When you create a new MoSync project, MoSync defaults to a generic device profile. You can find this profile in the Device Profile view under Mobile Sorcery > Emulator. The default device profile has the following characteristics:
- Platform: JavaME
- Bluetooth: yes
- MMAPI: yes
- Screen size: 240 x 320
You can use the default profile when you start to explore MoSync, and for many of our basic tutorials, but sooner or later you will want to test your application by setting up the emulator to use another device profile.
Changing the Emulator's Device Profile
The device profile that the emulator currently uses is highlighted in the Device Profile list with an orange background. To make the emulator emulate another device, right-click on a device in the Device Profile view and select Set Target Phone.

If you want to see more information about the device, select Show Profile Info from the right-click menu. You will then see the header file that MoSync will use when it builds the application for the emulator.
Configuring the MoSync Emulator
Currently, the only property you can change is screen size. You can manually override the screen size setting by clicking the small down-arrow next to the Run button in the toolbar, and selecting Run Configurations:

If you debugging your application, there is a similar setting for debug mode: click the small down-arrow next to the Debug button in the toolbar, and selecting Debug Configurations to see the settings.
Debugging in the MoSync Emulator
When a MoSync application terminates because of a panic, a call stack is transmitted to the output console in the IDE:

The call stack shows you all the stack frames that were active when the application terminated, and you can click on each line to go to the corresponding source file and line. This is the format of such lines:
IP:<instruction pointer>: <path to source file>:<line number in source file>
If the panic involved MoSync libraries that you do not have the source code to, those lines will not be clickable.
Displaying Build Results in the Console
When you build your project for the emulator, the progress of the build will be displayed in the Console and includes information about the success of the invokations of GCC and Pipe-Tool, the build paths, and so on. If you build your project successfully, these results will be replaced at the end of the build process by a new Console view showing the output from your application. If you want to examine the build results, you can switch the Console view using the Display Selected Console selector on the Console toolbar:

Installing and Working with Native Emulators
MoSync 2.6 onwards:
If you would like to run your application
directly in the Android Emulator or iPhone/iOS Simulator you will need to install and configure them. Once you have done this, when you select an Android or iPhone/iOS device profile and start the emulator, your application will run in the appropriate emulator.
- To be able to use the iPhone Simulator from the IDE, you need to be using the MoSync SDK for OS X on an Apple Mac.
- To be able to use the Android Emulator from the IDE, you can use either the MoSync SDK for OS X on an Apple Mac, or the MoSync SDK for Windows.
- On both Windows and Mac OS X you can, of course, still use MoSync's MoRE Emulator.
Installing the iPhone simulator
- Install the MoSync SDK for OS X, including Xcode 4 with iPhone SDK support. For full instructions, see Installing the MoSync SDK for OS X.
Installing the Android emulator
- Install the MoSync SDK for Windows (instructions: Installing the MoSync SDK for Windows) or the MoSync SDK for OS X.
- Install the Android SDK and use the AVD manager to install at least one platform to emulate (see Google's instructions for Installing the SDK).
- Start the MoSync IDE.
- Specify the location of the Android SDK. On Windows, open Window > Preferences > MoSync Tool > Android SDK. On OS X, MoSync IDE > Preferences > MoSync Tool > Android SDK.
- In the SDK location field, enter the absolute path of where you installed Android SDK. (This directory usually contain directories such as "tools", "platforms", etc).
Launching a MoSync application on a native emulator
- Make sure you have prepared your environment as described above.
- In the MoSync IDE device profiles list, select either an Android or an iOS device.
- Click the
Run button.
Important! Those of you who are already familiar with the Android Emulator will know that it can take a long time -- and we mean a really long time -- to start. Time enough, indeed for you to make lunch, or even dinner. Nothing to do with us. Talk to Mr Google.
- Printer-friendly version
- Login or register to post comments
Share on Facebook