Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__ANDROID__ macro suddenly not defined

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)
like image 668
La bla bla Avatar asked Mar 10 '13 22:03

La bla bla


3 Answers

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
like image 149
deltheil Avatar answered Nov 14 '22 10:11

deltheil


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

like image 45
Андрей Вахрушев Avatar answered Nov 14 '22 10:11

Андрей Вахрушев


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.

like image 29
La bla bla Avatar answered Nov 14 '22 12:11

La bla bla