This is really frustrating
- I can build my native code from command line, but when I build from eclipse(Sequoyah plug-in enabled) its simply through simple compilation errors like headers not found...
EVen when i build the library from command line everytime I try to run from eclipse it rebuuilds and there goes errors again
- I'm frustrated as I ran out of option to locate the issue
Can some one shed some light on this.
The error you are seeing is Unresolved inclusion with error markers at each header that Eclipse's editor cannot find. This is confounding when you see it, because it is expected that after installing Sequoyah and the ADT, pointing the Sequoyah configuration to your NDK, that you'd have everything you need to start coding.
Two things to observe. The process of building in the ADT "Android Perspective" will work until you click on one of your C/C++ files in your jni directory. Once you open one of these, you'll see the error marker and the project will be tagged as containing errors.
Second observation, when you convert the project to C/C++ perspective or to Sequoyah's Android Native perspective (apparently there's two ways to skin this cat), you will have the ability to configure the project settings around NDK toolchain, include paths, and builder settings. This is where you can set the ndk-build to automatically fire off on each change. And funny thing too is that the ndk-build will work fine until you click on one of your C/C++ sources.
So solution, click [here] http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/tasks/cdt_t_proj_paths.htm and you'll get instructions for configuring the CDT's include paths. You want to set your include paths for C/C++ (either, or both) so that you get to the platform folder includes.
Example, I've got my project hello-jni-to-the-world project set to android-9. So configure the include path: android-ndk-r6b/platforms/android-9/arch-arm/usr/include . Now the magic won't show up until you click apply/save and you'll be prompted to rebuild the indexes.
There are two to three other threads on Stackoverflow asking the same question, and I'll have to find them and add them to the comments. Basically, there were no definitive answers and there's a lot of the usual answering a question with a question: which version of NDK do you have, can you post your code, did you install java, is your computer on ?
Related
I have an Android/Eclipse project that uses the NDK and I've recently enabled c++11 support by adding the following to my Application.mk file:
NDK_TOOLCHAIN_VERSION := 4.8 #same result here with clang
APP_CPPFLAGS += -std=c++11
This basically works fine, c++11 features are available and compile as expected. This goes for ndk-build and Eclipse builds (which just invoke nkd-build), but the eclipse code parser becomes confused now. When I open a file that uses types added to the STL in c++11 (like for example std::unique_ptr), I get red squiggles and an error entry in the Problems tab saying Symbol 'unique_ptr' could not be resolved. This wouldn't be so bad, but if errors are present in that list Eclipse refuses to launch (or debug) the application. Right-clicking on the #include <memory> line and selecting Open Declaration also opens the wrong (4.6) file.
When checking the project properties under C/C++ General --> Paths and Symbols --> Includes it still lists the old (4.6) includes when Show Built-in values is ticked: Screenshot
Are those just cached from somewhere and I can get it to re-generate those entries? I've obviously tried to Clean and Rebuild the project, with no effect. I'd rather not add them manually if that can be avoided, upgrading the NDK to new versions already requires quite a few changes until it compiles again. Where are these entries generated from and how do I trigger an update?
I wish I could say I have a definitive answer for you, as I've been battling this problem for quite a while myself, but I do have a decent workaround. For starters, the "built-in" entries under "CDT Managed Build Setting Entries", are generated based on the contents of your Application.mk file which is located in the jni directory. There is no other way of changing them, and these are what populate the "Includes" section in the C++ perspective's Project Explorer. But I see that must have read the documentation.html in the NDK installation to see what to put in that file already. The issue then becomes that as soon as you change something or breathe too hard, your includes suddenly and irreversably become unresolved. The workaround for this is to recall the exact path of each include entry, right-click on the project, go to New->Folder, then in the dialog click Advanced, and select Link to Alternate Location (Linked Folder). Then navigate to the path (or extend a variable if you are fancy) of the include folder, rename it something descriptive (you can't have 4 linked folders named "include"), and voilà! You suddenly have a usable workspace again. I guess the "Includes" section functionality is a bit flimsy still, at least for ADT, and doing this puts the includes on the same footing as other files that are actually in your project. I'd be thrilled if the officially sanctioned mechanism started to work reliably, and I eagerly await news of such. HTH!
I'm developing a native application using Eclipse for Mac and I can't get std::string or std::map to resolve.
I've already had to add a number of include directories to the path to handle the NDK not being set up that well out of the box; currently I have
.../Development/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.8/include
.../Development/android-ndk-r9/platforms/android-18/arch-arm/usr/include
.../vuforia-sdk-android-2-6-10/build/include
.../android-ndk-r9/sources/cxx-stl/system/include
set as C++ symbol paths, and #include <string> seems to have worked fine. However, all the references to std::string are not resolving, and Eclipse says
Type 'std::string' could not be resolved.
I know this code builds because I successfully built it on a Windows PC; it's an eclipse problem of some description. What can I do to make these symbols resolve?
EDIT 1: I've looked inside <string> and it seems that it mainly contains a bunch of other includes, for example #include <bits/c++config.h>. All of these seem to resolve, but I am going to see if I can find them and determine where std::string actually lives.
EDIT 2: I can find std::basic_string, but not std::string (yet).
EDIT 3: std::basic_string is not apparently visible to my source code either.
Im not sure if this will be an answer for you. My experiences are different, I'm on Windows, and I was only trying to get C (not C++) code working. But ran into exactly the same issue. And my solution could seemly be used to work for C++ as well. As far as I can tell, Eclipse/ADT on Mac is much the same as on Windows. So that shouldn't be a problem here. Who knows, I could be talking out of my a--.
However, I think the problem is solved two fold. Here is how I solved it. I followed the tutorial: http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/
Things to note:
1) When developing in Eclipse/ADT for Android. It always assumes that your writing in Java. You need to make the project "Mixed Java & C/C++" (not that I've seen it called this outside the tutorial, lol)
2) Your ndk-build should probably work fine from the command line (even tho it might not compile in Eclipse).
3) In the tutorial, the two things that seemed to get it to recognize C/C++ are "Step 5: Convert to a C/C++ Project" followed by Steps 6-8 (which seem like one big step).
4) In Step 7, under "Build command". You might have to use a the complete path (no spaces) to your ndk-build. (*Windows users enter "ndk-build.cmd" here)
5) In Step 8, also include a full path.. no spaces. However, this is where you would put a path in for "GNC C++" instead. (This is my guess for your solution)
6) If all else fails... It should work in C. Try Step 8 exactly, and use only C syntax. Because, at the top of this older tutorial (http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/) it talks about how limited NDK is. It says C++ functionality is limited. Otherwise, this second tutorial is mostly obsolete it seems. Cygwin and command line compilation are not needed anymore, and my Eclipse installation had the C/C++ support out-of-box. However, its all still usable/valid.
PT
(and on a similar note, and for those seeking help with NDK. Also make sure a space-less full path to your NDK folder is entered in at Eclipse > Window > Preferences > Android > NDK > NDK Location)
NOTE: it apparently is a recurrent question on StackOverflow, but - for what I have seen - either people never find a way or their solution does not work for me
The problem:
I am using Eclipse Juno ADT. Everything was working fine until I tried to update the NDK. I replaced my ndk folder (that was the ndk-r8d) by the new version (i.e. ndk-r8e) and, in my Paths and Symbols configuration, I changed the includes to go from g++ 4.6 to 4.7.
It seemed to break my index: I could compile my code, but Eclipse was giving semantic errors, exactly like in [1] and [2]. The errors mainly come from symbol used by OpenCV4Android, such as distance, pt, queryIdx and trainIdx.
When I tried to backup to my old configuration, the index was still broken! I cannot find a way to change this.
What I have tried
Clean up the project
Rebuild, refresh, and all the other options in the "Index" submenu (when "right-clicking" on the project)
Disable / enable the indexer in the preferences
Verify that symbols such as trainIdx only appear in my OpenCV4Android include in the Paths and Symbols section.
Change the order of my includes in the Paths and Symbols section. I basically tried to put the OpenCV include in the beginning and in the end.
Some observations
What is not working
I assume that it is the CDT index because of the following:
In command line, I can build my project using ndk-build clean and ndk-build.
When I start Eclipse, I have no error until I open a C++ file (from the jni folder).
I can always build the project, but as long as I have opened a C++ file, I can't run the application anymore because of a lot of Field '<name>' could not be resolved.
If I don't open the C++ files, Eclipse doesn't report any error and can build and deploy the Android application successfully.
Interesting fact
The following code reports errors on line, queryIdx, pt:
cv::line(mRgb, keypointsA[matches[i].queryIdx].pt, keypointsB[matches[i].trainIdx].pt, cv::Scalar(255, 0, 0, 255), 1, 8, 0);
If I write it as follows, it works:
cv::DMatch tmpMatch = matches[i];
cv::KeyPoint queryKp = keypointsA[tmpMatch.queryIdx];
cv::KeyPoint trainKp = keypointsB[tmpMatch.trainIdx];
cv::line(mRgb, queryKp.pt, trainKp.pt, cv::Scalar(255, 0, 0, 255), 1, 8, 0);
It is not that all of the OpenCV functions are unresolved: only pt, queryIdx and trainIdx are.
Any comment will be really appreciated.
In your selected project preferences within the Eclipse environment, go to C/C++ General -> Code Analysis -> Launching. Make sure that both check boxes are unchecked. Close and reopen the project or restart eclipse and rebuild the project.
Since indexing for Android native code on Eclipse is incomplete, I managed to enable indexing in my NDK projects the following unintuitive way, it should work whether you use ndk-build or plain make or even cmake. I'm using Kepler but it should work on older versions too.
Get your toolchain right
Right click on project -> Properties -> C/C++ Build -> Tool Chain Editor -> Uncheck Display compatible toolchains only.
In the same window, set Current toolchain to Linux GCC.
In the same window, set Current builder to Android Builder if you're using ndk-build, set it to Gnu Make Builder otherwise (this step may be wrong, sorry in advance if it is).
Right click on project -> Properties -> C/C++ Build -> Build Variables -> Make sure Build command reads the correct command for your project; if it's not, uncheck Use default build command and correct it (it may be ndk-build or make -j5 that you want). If you build the native code in a separate terminal, you can skip this step.
Make a standalone toolchain, it's probably the cleanest way to get STL sources in one place
Go to the NDK root directory.
Run the following (tweak the settings according to your liking). Add sudo if you don't have write permissions to the --install-dir because the script fails silently.
./build/tools/make-standalone-toolchain.sh \
--platform=android-14 \
--install-dir=/opt/android-toolchain \
--toolchain=arm-linux-androideabi-4.8
This is assuming that you use GNU-STL. If you use another C/C++ library, you will need to tweak the above command, and probably also the include paths in the next command.
Add the necessary include paths to your project
Right click on project -> Properties -> C/C++ General -> Paths and Symbols -> Go to the Includes tab -> Select GNU C++ from Languages -> Click Add and add the following paths (assuming you installed the standalone toolchain to /opt/android-toolchain):
/opt/android-toolchain/include/
/opt/android-toolchain/include/c++/4.8/
/opt/android-toolchain/include/c++/4.8/arm-linux-androideabi/
/opt/android-toolchain/lib/gcc/arm-linux-androideabi/4.8/include/
/opt/android-toolchain/include/c++/4.8/backward/
/opt/android-toolchain/lib/gcc/arm-linux-androideabi/4.8/include-fixed/
/opt/android-toolchain/sysroot/usr/include/
Here, you can add every include path you want. In fact, I have my OpenCV built for Android and installed in the standalone toolchain, so I have the following include there:
/opt/android-toolchain/sysroot/usr/share/opencv/sdk/native/jni/include/
Now, the indexing should work. You should also be able to run ndk-build (or make if that's your build method) and then deploy your project to your device inside Eclipse.
Why?
Android native development on Eclipse is incomplete since the indexing doesn't work out of the box. This is due to having to support multiple architectures (ARMv7, Intel etc.), multiple STL options, multiple Android versions etc. This is why you have the bare make based ndk-build and the whole NDK structure, and this is also why NDK development is very unclean and few large volume native Android projects exist.
A big Android project is OpenCV where they had to develop a 1500 odd line CMake script to get it to compile for Android properly. At some point, they tried to export that script as a CMake based build system for Android but it couldn't keep up with the changes in the NDK system and was abandoned. This support should have been inside NDK itself.
The default NDK build system should have been standalone toolchain only, with all different architectures/C++ libraries having their own toolchains at the cost of storage space but with the advantage of cleanness, intuitiveness and good practice. Then you can incorporate any standard cross-compilation system that is also used elsewhere, is tested and is well-known, e.g CMake. You can, and in my opinion you should, do that with the NDK's make-standalone-toolchain command as shown above. But in the end, this is only my opinion. If you feel comfortable enough with ndk-build then go ahead.
It's actually quite hard to say what is the problem. Here are some advices:
Try to import and build hello-jni (it is located in jni's samples folder). If it runs without problems than problem is with linking OpenCV to your project.
It seems that you forgot to update android-ndk location in project properties -> c/c++ build -> environment. Here's link to problem Issue with build Android NDK project.
Build from console your project (ndk-build -B), delete all errors in Eclipse manually (in Problems view select all errors and just click delete) and try to run project now. Sometimes this "hack" helps me to run project.
Close Eclipse and delete folder path-to-your-workspace/.metadata/.plugins/org.eclipse.cdt.core (backup it first).
Go to Preferences > C/C++ > Language Mapping > ADD (Source C File and select GNU C) Do the same for C++
I had the same issue. I had all the proper include paths setup but after opening the .c/.cpp or .h file and it would start marking everything as "Unresolved."
This worked for me...
Go to:
PREFERENCES -> C/C++ -> INDEXER
Check Index Source And Header Files Open in Editor.
I had the same issue, like many people.
I followed the steps in Ayberk Özgür post, which make good sense. Although I also had to make sure to put includes under all three languages: GNU C, GNU C++, and Assembly. Probably because I'm not using a stand alone tool chain.
I at first had my includes only under GNU C and GNU C++ languages. Which left me still with the unresolved includes error. Not until I assigned my includes under the Assembler language as well did my errors go away.
I do not know why eclipse is only searching through the Assembler includes in my project. I also do not know how this part of the solution will work for bigger more complicated projects.
Hope this helps.
I had the similar situation with Eclipse CDT working with the OpenCV library. I got several error messages while the program compiled correctly. I changed the indexer setting in "window->preferences->Indexer" "build configuration for indexer" box to "Use Active Configuration" which solved my issue.
I just spent about 3h banging my head against this Eclipse NDK indexing issue!..
What made it work: make sure that you have only ONE cpu architecture specified in Your Application.mk file.
Otherwise the .metadata/.plugins/com.android.ide.eclipse.ndk/*.pathInfo file will not be generated by the NDK build. This file contains built-in values from Project -> Properties -> C/C++ General -> Paths and Symbols -> Includes (just making .pathInfo file does not fix the problem)
I have been given a program written in C, and have been asked to use the functions from the program in a new Android application. I have been following the tutorials of the NDK, but have hit a wall. I think all that is left is compiling or linking my C files, but I'm not sure. I have installed the SDK, NDK, Eclipse, Cygwin, and Sequoyah ( I haven't used Sequoyah yet and don't really know where it comes into play ).
I have used the ndk-build command, but am not sure what I am should be expecting. This is a screenshot of my Cygwin terminal.
This is a screen shot of my NWPTest.c file. All of the fields defined in the .h file come up as errors. I feel like this is an error that should go away once I compile the code.
BYTE and WORD etc. declarations here:
This is a screen shot of the NWPTest.h file. BYTE and WORD declarations are also coming up as errors, which is something I do not understand.
This screen shot basically shows the last thing as the last one, but I'm confused how some of the BYTEs are errors and some are not:
EDIT
Here is my Android.mk file. Just to clarify, I was given the entire C project, and was told to make it an Android application. I have no experience with C.
Probably your problem is that Eclipse doesn't know about the include path for the ndk C header files; however that should not really matter since ndk-build appears to have built your native library. Though if your C-aware eclipse setup is being obstinate and refusing to build the rest of your project with "errors" in the C files, then you will have to either fix the include path or tell eclipse to ignore the C files as it does when not aware of C.
Of more concern would be whatever is causing an error in Operations.java - that will prevent you from building an apk.
I guess this is eclipse error. It simply does not understand your c and h files. Try to install CDT plugin, maybe after that the problems will eliminate.
A project that I am trying to build has one of these, and I want to know exactly which tools are needed to build the project. I see some reference to NDK when I search but is that the only tool? It appears that this file is making a jar file, I see no reference to native code ( c++ )
The Android.mk files in the SDK samples are required to properly include the samples in the SDK build (if you are actually venturing into that territory). These have no bearing on what you are doing when you use the sample. To the OP, I'm not sure if you are using a sample project, but if you are, you can ignore this file.
the best answer to your question is reading this article:
Android.mk file syntax specification
https://android.googlesource.com/platform/ndk/+/4e159d95ebf23b5f72bb707b0cb1518ef96b3d03/docs/ANDROID-MK.TXT
after reading it you can figure out the idea behind the android.mk file.
cheers
I've seen some of the Android sample code come with an Android.mk file for no apparent reason -- maybe this gets auto-generated upon project creation if you happen to have the NDK installed or something. Android.mk does seem to be an NDK-specific thing.
So if there's really no native code involved, then if you're looking to build from the command line, make sure you have the JDK, Ant, and Android SDK installed.
Then take a look at
http://developer.android.com/guide/developing/projects/projects-cmdline.html#UpdatingAProject
After you run the "android update project ..." step, you should hopefully be able to do an "ant debug" to build the application.