__ANDROID__ macro suddenly not defined

10,360

Solution 1

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.

Solution 2

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

Solution 3

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

Share:
10,360

Related videos on Youtube

La bla bla
Author by

La bla bla

Updated on June 04, 2022

Comments

  • La bla bla
    La bla bla almost 2 years

    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.

    I followed this http://tools.android.com/recent/usingthendkplugin tutorial, but NDK_DEBUG = 1 tag to my build command, suddenly I started getting errors in the code which didn't go away even after removing that tag, changing from Android 4.2.2 back to 2.2, changing the NDK I was using, or anything else I could think of.

    The problems happens now inside statements like this

    #ifdef __ANDROID__
    some cool android code
    #else
    some pretty awesome iOS code
    #endif
    

    what happens it that the __ANDROID__ is for some reason not define, causing eclipse and ndk-build to try and compile the iOS code instead of the Android's

    Reverting everything I did didn't seems to have any effect. Restarting eclipse didn't as well. Cleaning the project, completely delete libs and obj directories didn't work too..

    Any suggestions?

    Thanks!

    EDIT:

    Maybe it's worth adding that the build itself, using ndk-build completes successfully. I think it might be an eclipse issue, but even if so, it still an error and I can't launch the app

    Also, just in case, restarting the computer didn't work either.

    EDIT 2: The problem exists on another computer running the same workspace over network, my guess was something related to the workspace, so I tried deleting .metadata folder and adding the project again.

    Deleting the .metedata folder fixed it the 1st time, but after a few minutes (in which I managed to build and run the app on my tablet) the same issue returned, and deleting the .metadata didn't work

    EDIT 3:

    Still no go.

    However, I can confirm that it's not a project specific problem, as all the projects that has Native support in eclipse now do this.

    Other things that doesn't work:

    • creating an empty project, adding Native support.
    • Completely changing to another unrelated workspace and perform the above tests
    • Downloading fresh version of eclipse (juno), CDT & ADT (was using the eclipse ADT bundle)
  • La bla bla
    La bla bla about 11 years
    Hi, thanks for the answer. Unfortunately, doing so didn't change anything. Still the same problem..
  • deltheil
    deltheil about 11 years
    What I suggest you is to trigger verbose outputs with ndk-build V=1 and inspect what's going on within your build commands, i.e. is -DANDROID present?
  • La bla bla
    La bla bla about 11 years
    Thanks, I did it now, and -DANDROID is there. Also, it seems that the C code is compile well, the .so library file is being generated. it's as if eclipse itself doesn't recognize these flags, cause even though the c code appears to have error when viewed in eclipse, it compiles as it should

Related