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
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.
trainIdx
only appear in my OpenCV4Android include in the Paths and Symbols
section.Paths and Symbols
section. I basically tried to put the OpenCV include in the beginning and in the end.I assume that it is the CDT index because of the following:
ndk-build clean
and ndk-build
.jni
folder).Field '<name>' could not be resolved.
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.
Properties
-> C/C++ Build
-> Tool Chain Editor
-> Uncheck Display compatible toolchains only
.Current toolchain
to Linux GCC
.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).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.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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With