Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

android - __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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...