How to set a #if or #define conditionally?

Asked

Viewed 37 times

0

Good afternoon, everyone...

I’m helping a staff to make a PC game mod compatible with their Android version (Stardew Valley). The problem is that I need to use methods that only exist in the android version to draw in HUD.

The two versions of the game have the same DLL, but with some different methods. I thought of using the #if and #endif to specify these methods in without giving build error, but the problem is the definition of that if.

How do I specify this #if to be processed only if it is android? Or how I could create a conditional #define for android?

PS. Creating a version for each platform is not an option.

  • Did you install the Android sdk and set everything right in your project? What didn’t work? Introduce a [MCVE]

1 answer

1

If you want this snippet of code to only run when it comes to an android device, you must indicate in #if

#if __ANDROID__
// seu código para Android
#endif

You can even define different behaviors for different levels of compatibility

#if __ANDROID_11__
// código para o Honeycomb e versões posteriores
#endif

For more information, read the Microsoft documentation: https://docs.microsoft.com/pt-br/xamarin/cross-platform/app-fundamentals/building-cross-platform-applications/platform-divergence-abstraction-divergent-implementation

  • That was the first thing I tried and it didn’t work =/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.