Are the conditional compilation constants __ANDROID__ and ANDROID the same or different?

dg2k 1,391 Reputation points
2023-10-24T17:09:16.08+00:00

The conditional compilation directives #if ANDROID and #if __ANDROID__ are used as if they are different, or are they? For example, you can see their usage in .NET MAUI sample projects.

Are these constants the same, and if so which one is the official?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,062 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 37,581 Reputation points Microsoft Vendor
    2023-10-25T02:07:40.61+00:00

    Hello,

    Both forms currently work exactly the same in MAUI.

    According to explain the difference between #if __ANDROID__vs #if ANDROID #501, using #if ANDROID is a better option.

    In the earlier .NET MAUI releases #if ANDROID didn't work but #if __ANDROID__ did work. However, since then #if ANDROID works. They've since been equivalent. The preferred and recommended approach from the product team is to use #if ANDROID. There's no guarantee that #if __ANDROID__ support will remain forever.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful