Android builds can be distributed using a digital store (such as Google or Android), or can be manually distributed by distributing a .apk.
Before you perform any distribution, you must create a release build of your app.
The following will walk you through creating a release build. Release builds can be created for any FlatRedBall Android project, including synced Glue projects. This walkthrough assumes that you have an Android project which you have been able to successfully deploy to device through Xamarin Studio or Visual Studio.
If using Xamarin Studio, change the configuration to release:
Release builds are required for distributed .apk files.
Distributed builds also require linking against the release build of FlatRedBall. If using the .dll files which are distributed with the FlatRedBall templates (default), then your project will already have the release files downloaded.
These can be found in your project's Libraries folder:
To link the release files in Xamarin Studio:
Right-click on your game project's References
Select "Edit References..."
Select the ".Net Assembly" tab
Un-check the FlatRedBallAndroid.dll file
Click the "Browse..."
Navigate to the <project folder>/Libraries/Android/Release folder
Select FlatRedBallAndroid.dll and click Open
Verify that the release build of FlatRedBall is added and click OK
Once this library has been added, build and run your project to make sure everything is working fine.
The project needs to specify the architectures it will support. Unless you are concerned about file size, you should support all architectures. To do so:
Right-click on your project
Select "Options"
Select the "Android Build" option
Click the "Advanced" tab
Check the desired supported architectures:
The .apk file is what you need to distribute to test it on other phones. In Xamarin Studio:
Select "Project" -> "Create Android Package..."
Enter a name in the "File:" text box for the desired .apk file name
Click OK
Once the .apk file has been created it can be distributed through any digital means, such as google drive, drop box, or sending the file through email.
Xamarin's Android compiler includes a feature which allows selective inclusion of libraries, classes, and members. This feature can reduce the size of a game, but also can introduce crashes which can be difficult to diagnose - at least unless you know what to look for.
The most common type of crash occurs when deserializing XML files, such as emitter .emix files. If your program runs fine in debug but crashes in release, then it may be related to Xamarin's linking behavior. You can verify that this is the case by looking at the output window. For example, the following error appears when trying to load a .emix file.
One way to solve this problem is to adjust the linking behavior, which can be done as follows:
Right-click on the project in the Solution Pad
Select "Options"
Select the "Android Build" category
Click the "Linker" tab
Change "Link all assemblies" to either "Link SDK Assemblies only" or "Don't link"
Try running again and see if the crash occurs
The downside to this solution is that these will increase the size of your APK file.
For more information on linking, see this article.
FlatRedBall supports creating games which run on Android devices. Aside from Android-specific capabilities, FlatRedBall Android development is nearly identical to developing games for other platforms. As of April 2024 FlatRedBall Android projects use .NET 8 which provides access to a much wider set of features and nuget packages compared to the previous Xamarin-based version.
FlatRedBall Android game development requires a Windows PC just like regular PC game development as well as Visual Studio 2022 or newer.
As mentioned in the Multi-Platform page, the recommended approach for creating full game projects is to create a primary desktop project with a synced Android project. However, if you are evaluating FlatRedBall, or creating a small test project, you may want to create a primary Android project. Both approaches are discussed below.
Creating an Android project is essentially identical to creating any other platform:
Open the FlatRedBall Editor
Select File->New Project
Enter a project name
Set the Platform to Android .NET
Click Create project!
Select the desired project type in the wizard, or close the wizard to begin with an empty project. Click the Visual Studio icon to open the project in Visual Studio:
Now that the project is in Visual Studio, you can develop an Android game the same as if you were making a PC game, including using the FRB Editor. To launch the game:
Select the target device
If you have a physical phone, you can connect it to your computer. You need to enable your phone for development by turning on developer mode. For more information see the Microsoft page for setting up an Android device: https://learn.microsoft.com/en-us/dotnet/maui/android/device/setup?view=net-maui-8.0
If you do not have a physical phone, or if you prefer to use an Android emulator, see the following page on how to set up an Android emulator: https://learn.microsoft.com/en-us/dotnet/maui/android/emulator/?view=net-maui-8.0
Verify that the Play button in Visual Studio has the desired emulator or device selected. Note that if a physical Android device is connected to your computer and is set up for debugging, then Visual Studio will detect it as a deployment option.
Press the Play button
Synced Android projects are created just like any other synced project. The first step is to create a regular Windows Desktop project. Once the project is created a new synced Android project can be created as follows:
Open FlatRedBall
Select Project->View Projects
Click the New Synced Project button
Select the Android option
Enter a project name
Click Make my project!
The project will take a moment to download and be created, but once it is, you should see the Android project listed in the Androids project list. Since your FlatRedBall project now has multiple platforms, you can choose which project to open through the Projects tab.
To create an Android APK, whether for internal testing or for final release, see the Microsoft release documentation.
Unfortunately deploying to Android can be fickle at times, and sometimes no errors are provided.
If your app crashes immediately without a call stack, then you may want to try the following:
Does the app work on Android hardware? Sometimes an app will not work on emulator but will work on hardware
Have you tried creating a .NET MAUI? MAUI projects can be created with templates which are part of Visual Studio, so they are likely to eliminate common problems in template setup. If a MAUI project doesn't work, then that might mean that prerequisites are not properly installed.
To create FlatRedBall Android projects, you must:
Install Visual Studio as explained on the FlatRedBall Downloads page.
In the Visual Studio Installer, check Mobile development with .NET
If it isn't already installed, click the button to install
Wait for the installation to finish.
Once you have finished installing, you can verify that you have Xamarin installed:
Open Visual Studio
Select Create a new project
Search for Xamarin to make sure that Xamarin is installed. If you see search results for Android or iOS development, then it is installed
You're al set up. Now you can begin making Android applications. For information on creating a new Android project, see the main Android page.