#if !ANDROID not working

I have some code in that I only want to run on Desktop (GL) and some code that I only want to run on my Android device.


    IsMouseVisible = true;
    camera.Zoom = 0.325f;

And somewhere else:

    camera.AnimateTransformTo(new Vector2(200f, 100f), 0.325f, 80f);
    camera.AnimateTransformTo(new Vector2(200f, 100f), 1f, 80f);

Doesn’t matter if i am on Desktop or Android. The game allways runs the !ANDROID part.
Is there any place where I can look up ALL possible definitions? because I found ANDROID, I found __ANDROID__, i found __MOBILE__ (…) but I have no clue if they work for monogame or not or if I should be using something else. Where Is the documentation on this?

How is your project setup? Is the code inside your android project?
Because if this code is used by both projects and is located in another project (e.g. you compile it to a dll) the defines won’t work.
A workaround might be to have a bool variable in your shared-code-project that you can set from within the desktop- or android-project

I don’t know if it can work on Android or either Linux etc, but you could try:
Environment.OSVersion to check the current OS the app is running on ?
or OperatingSystem.Platform from the System namespace ?

Yeah, the defined symbols by MonoGame are handled by the preprocessor and are no longer present in the compiled assembly. So if you want to use the symbols like this you have to define them yourself for your projects.

Yes, I am using 3 projects. One for DesktopGL, one for Android, and the third one contains The Game Class and the Game Content. (Game Content is copied into the other projects pre-build, because I couldn’t get it to work with the shared project)

I’m a bit confused right now. Where should I define what? O,o

Right click on the “AndroidTest” project and open the properties. In the “Build” tab at the top there is a “Conditional Compilation Symbols” text box, type the word ANDROID in there.

However if you’re defining those “#IF #ENDIF” statements in the Shared project, then the above won’t work, what you will need to do is have parameters in the methods and pass in a parameter/constant which you can define in the two main projects.

1 Like

Okay, now I got it. Thank you sir!

Game Class Constructor:

public MonoControlsTest(Platform _platform) {
   platform = _platform;


public enum Platform {
   LINUX = 1,
   ANDROID = 2


static void Main() {
   using (var game = new MonoControlsTest(Platform.LINUX))


protected override void OnCreate(Bundle bundle) {
   var g = new MonoControlsTest(Platform.ANDROID);


if (platform == Platform.LINUX) {
   IsMouseVisible = true;
   camera.Zoom = 0.325f;

You’re welcome, glad to help where I can.