__ANDROID__ macro suddenly not defined

后端 未结 3 1941
清酒与你
清酒与你 2020-12-16 06:42

I\'m working on an app which uses NDK (all I\'m writing happened both on r6b and r8d)

Everything was working fine, and I wanted to start and try debugging my C code.

相关标签:
3条回答
  • 2020-12-16 07:12

    Apparently __ANDROID__ is a specific GCC macro that it supposed to define internally whenever correct options are provided. However, since control over options is largely delegated to NDK, one should not rely on __ANDROID__ macro being ever defined. The compiler behind NDK might not be GCC for all we know (or care). When working with NDK, check for ANDROID.

    Edit: clang now also defines __ANDROID__ macro

    0 讨论(0)
  • 2020-12-16 07:17

    Just so you know:

    • when you work with Android.mk file(s) and ndk-build, the ANDROID macro is predefined (see -DANDROID extra C flag when building with verbose outputs),
    • but if you use the Android Standalone Toolchain, then __ANDROID__ is predefined instead.

    So I suggest you to use:

    #if defined(ANDROID) || defined(__ANDROID__)
      /* ... */
    #endif
    
    0 讨论(0)
  • 2020-12-16 07:23

    If anyone else encounters this issue:

    I opened the workspace on another computer (Workspace is in a Dropbox folder), and the problem was still there on the other computer, which could only mean a workspace issue, so I delete the .metadata folder from the workspace.

    I had to re-add the projects, but after doing so, everything seems to work now.

    0 讨论(0)
提交回复
热议问题