Developing for Android

The following steps outline the basic procedure for using Visual Studio and Xamarin tools to develop for Mono on Android devices. Most of these steps describe Visual Studio and Xamarin features and procedures (some of which change often), so see Visual Studio and Xamarin documentation for full information.

Tip

You can use the Synergy Android Application project template to quickly get a simple application up and running on an Android emulator or device. See Android quick start (Hello World).

Synergy .NET support for Android is similar to its support for Windows desktop and server applications (see Developing Windows Desktop and Server Applications), but there are differences. Windows-specific code won’t work with Android (for example, file paths for Android must have forward slashes) and there are different restrictions, special defines, templates, and so forth. Many of these are discussed below, but see Feature Support for more information.

Additionally, any Android solution with a Synergy project must implement Synergy device licensing, though licensing is not used when running on an emulator. See Licensing .NET assemblies.

1. Start by reviewing Synergy .NET Requirements. Your Windows development machine and the Visual Studio projects you develop must meet the requirements listed there. For testing and debugging, you will need to use an Android emulator within Visual Studio or an Android device connected to the Windows development machine. (See step 2 in Building, debugging, and deploying Android applications.)

1. Components for Android development.

Components for Android development

2. In Visual Studio, create a project for each assembly in the Android application. The following Synergy templates can be used for Android projects:

For example, to create an executable assembly, select File > New Project, select Synergy/DE > Android from the Installed Templates area of the New Project dialog, and then select Android Application from the list of project types. You’ll then need to set a few options for the project (name, location, and so forth) in the New Project Dialog. Note the following:

3. Add DBL code, resources, assets, controls, etc., to the Visual Studio projects, and make sure each project references all needed assemblies.
while(UIApplication.SharedApplication==^null)
    await Task.Delay(100)
4. Set project properties. See Synergy/DE project properties, and note the following:

Building, debugging, and deploying Android applications

For Android debugging, use one of the following:

Note that the Google ARM emulator, which comes with Xamarin, is very slow to start (it generally takes several minutes).

Before you start, make sure debugging files are set up. See http://www.synergex.com/synergy_net.aspx.

1. Build the Visual Studio projects. For an Android Application, Xamarin creates an Android package (.apk) at build time. This package is what you deploy to devices.
2. For debugging and deployment testing, use an Android emulator or an Android device that’s configured for development (i.e., set to developer mode with USB debugging enabled) and connected to the Windows development machine. You can select the emulator (which must be API level 14 or higher) or the device in the Target Android Device toolbar drop-down list.

For information on connecting to an Android device, see Synergex KnowledgeBase article 100002189.

For more information on debugging, see Debugging Synergy .NET Code.

3. When testing is complete, follow Xamarin instructions for preparing an application for deployment: disable debugging, specify an application icon, version the application, configure the linker so that the shared runtime is not used, compile in Release mode, and so forth.
4. Deploy the application via a website, an email, or an Android deployment site (e.g., Google Play or the Amazon App store for Android), or just install it on target devices.

Android quick start (Hello World)

If your system meets the requirements for Android development (see Synergy .NET Requirements), you can have a simple Synergy application running on an Android emulator in a matter of minutes.

1. Open Visual Studio and select File > New > Project. Then, in the New Project window, select Android Application (in Installed > Templates > Synergy/DE > Android):
2. Set options for the project (name, location, and so forth), and then click OK.

The new project will open in Visual Studio with the Activity1.dbl file open in the editor.

3. Find the assembly:SynergyDeviceLicense... line in Activity1.dbl, and enter dummy public key and GUID values for device licensing. In other words, add some characters between the quotes that follow PublicKey= and AppGUID=. In the following, for example, both are set to “abc”:

Although device licensing is not required when running on an Android emulator, the Android Application project template includes a full device licensing implementation, which requires PublicKey and AppGUID values. The application will not build without them.

4. In the Target Android Device toolbar drop-down list, select MonoForAndroid_API_15.
5. Select Build > Build Solution. The Output window should show that the build succeeded.
6. When the project has finished building, select Debug > Start Debugging. If a Launching Emulator window opens, click Yes.
7. Wait while the emulator opens and installs your application. This may take a few minutes. When it’s finished, your application should be running on the Android emulator (though you may have to unlock the device):

Congratulations! You have just created a Synergy .NET Android application. On an emulator, clicking the About Device License button will open a window with licensing information. (On a device, it prompts you for a user, a password, and a description.)