Ask Your Question
0

I can't compile JNI file

asked 2013-10-29 17:12:21 -0600

lobi gravatar image

updated 2013-10-29 17:48:41 -0600

Hello,

This is the question I asked on stackoverflow., but nobody can help me.

http://stackoverflow.com/questions/19631634/cant-compile-android-project-wiht-jni-code-algorithm-not-found

I will ask the same question here. I'm trying to build simple android app with some JNI code. I already try this [suggestion][1], but isn't help

When I press build project in eclipse I get this error:

Description Resource    Path    Location    Type
fatal error: algorithm: No such file or directory   Tracker     line 56, external location: /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp  C/C++ Problem
make: *** [obj/local/armeabi/objs/detect_jni/detect_jni.o] Error 1  Tracker         C/C++ Problem

Line 56 in core.hpp contains the relevant include.

This is my Android.mk file jni folder:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

include /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := detect_jni
LOCAL_SRC_FILES := detect_jni.cpp

include $(BUILD_SHARED_LIBRARY)

This is my Aplication.mk file in jni folder:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
APP_PLATFORM := android-8

This is my .cpp file:

#include <jni.h>
#include <opencv/cv.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>

using namespace cv;

extern "C"{
    JNIEXPORT void JNICALL Java_com_slani_tracker_OpenCamera_findObject((JNIEnv *env, jlong addRgba, jlong addHsv);
    JNIEXPORT void JNICALL Java_com_slani_tracker_OpenCamera_findObject((JNIEnv *env, jlong addRgba, jlong addHsv)
    {

        Mat& rgba = *(Mat*)addRgba;
        Mat& hsv = *(Mat*)addHsv;

        cvtColor(rgba, hsv,CV_RGBA2HSV);

    }
}

![This is my path and symbols in eclipse

This is path to my ndk-build

Thanks

edit retag flag offensive close merge delete

Comments

-1 for just quoting a so question here. more effort, please ;)

berak gravatar imageberak ( 2013-10-29 17:17:46 -0600 )edit

Should I rewrite the same question???

lobi gravatar imagelobi ( 2013-10-29 17:38:59 -0600 )edit

Please help me

lobi gravatar imagelobi ( 2013-10-30 04:15:25 -0600 )edit

hey, i whish i could !

berak gravatar imageberak ( 2013-10-30 04:41:31 -0600 )edit

I'm very frustrated. I don't know what to do. I went through all steps thousand times.

I don.t know why ndk-build wont find android file. Very strange is, if I compile with ndk-build OpencCv samples it's build normaly. ndk-build finds all file. I also try include complete path to algorithme file in core file. But then I get error to find next file include in algorithm file.

lobi gravatar imagelobi ( 2013-10-30 05:29:53 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-10-30 05:59:10 -0600

ThomasB gravatar image

Hey,

don't give up that quick, might be a simple error. In your CPP-File:

JNIEXPORT void JNICALL Java_com_slani_tracker_OpenCamera_findObject((JNIEnv *env, jlong addRgba, jlong addHsv)

There is a ( too much at the beginning of arguments. Furthermore I'd recommend to configure the OpenCV-Type a bit more (see Android.mk later). I did a quick demo application that calculates the HSV-Value of an RGBA-Value and prints it to logcat as a fatal error. Your project settings seem to be correct (as soon as the ndk-build is invoked, everything is fine).

Build looks something like:

    11:56:03 **** Incremental Build of configuration Default for project testApp ****
/home/tbergmueller/bin/avEclipse/android-ndk-r8d/ndk-build 

Compile++ thumb  : testLibrary <= detect_jni.cpp
Prebuilt       : libopencv_contrib.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_legacy.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_ml.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_stitching.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_objdetect.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_ts.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_videostab.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_calib3d.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_photo.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_video.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_features2d.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_highgui.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_androidcamera.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_flann.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_imgproc.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : libopencv_core.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../libs/armeabi/
Prebuilt       : liblibjpeg.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../3rdparty/libs/armeabi/
Prebuilt       : liblibpng.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../3rdparty/libs/armeabi/
Prebuilt       : liblibtiff.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../3rdparty/libs/armeabi/
Prebuilt       : liblibjasper.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../3rdparty/libs/armeabi/
Prebuilt       : libIlmImf.a <= /home/tbergmueller/bin/avEclipse/opencv-2-4-5-android-sdk/sdk/native/jni/../3rdparty/libs/armeabi/
Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/
SharedLibrary  : libtestLibrary.so
Install        : libtestLibrary.so => libs/armeabi/libtestLibrary.so

11:56:05 Build Finished (took 1s.817ms)

As I stated, you might want to configure OpenCV in the makefile a bit (no camera modules). Furthermore I'd recommend to use libtype static for the opencv AND most important set the OPENCV_INSTALL_MODULES, otherwise they might not be exported to your device when you install the app.

To build the application, I used the following Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=STATIC

$(info $(NDK_MODULE_PATH))

include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk ...
(more)
edit flag offensive delete link more

Comments

Thanks for your answer. I try to use oure Android.mk but dosen't work. I get the same error. In file included from /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv/cv.h:64:0, from jni/detect_jni.cpp:2: /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp:56:21: fatal error: algorithm: No such file or directory compilation terminated. make: * [obj/local/armeabi/objs/testLibrary/detect_jni.o] Error 1

I don't get it. If run ndk-build in tutorial-2-mixedprocessing folder. It's build normaly.

But when I run in ndk-build in myproject folder. I get erros. But Android.mk filse is the same. Bouth .cpp files include the same things. What I did wrong.

P.S. I remove one bracket

lobi gravatar imagelobi ( 2013-10-30 14:21:03 -0600 )edit

Have you used my other files as well? probably something went wrong whilst adding C++ nature (have you added c++ nature or probably C-Nature?) however, It seems to be a quite uncommon error, I don't think I can help you from scratch, sorry. Such uncommon behaviour is often observed if there are syntax errors somewhere in the headers or include files - could that have happened? I hope you removed the bracket in the prototype as well - by the way, you don't need the function prototype here ;)

ThomasB gravatar imageThomasB ( 2013-10-30 16:47:00 -0600 )edit

I use all of your posted coode. I get the same error.

~/code/androCV/Test$ ../../android-ndk-r9/ndk-build

Compile++ thumb : testLibrary <= detect_jni.cpp In file included from /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv/cv.h:64:0, from jni/detect_jni.cpp:10: /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp:56:21: fatal error: algorithm: No such file or directory compilation terminated. make: * [obj/local/armeabi/objs/testLibrary/detect_jni.o] Error 1

And I get the same errors. How can ndk-build now in which files it should looks for header files? If we are using ndk-build comand in terminal I still don't know how can ndk-build comand on tutorial poject build libs, but in my porject wont do this.

lobi gravatar imagelobi ( 2013-10-30 18:25:03 -0600 )edit

Can you please send me your project?

Thanks

lobi gravatar imagelobi ( 2013-10-30 18:29:04 -0600 )edit

If I like to use JNI I should convert my android project to C/C++ poject and this automaticaly adds C/C++ Nature in Eclipse

lobi gravatar imagelobi ( 2013-10-30 18:38:22 -0600 )edit

Hey, here's the project, I'll remove the download in 2 or 3 days again, so make sure to download and save it ;) http://thomasbergmueller.com/share/testApp.zip Have you already checked what what the origin of the include error is? Does the file (algorithm.h???) exist on your filesystem?

ThomasB gravatar imageThomasB ( 2013-11-01 10:40:48 -0600 )edit

/home/slani/code/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.8/include

here I can find algorithm.

Very strange is, that tutorial .cpp inlcude same OpenCV file and nkd-build just fine (so it must finds algorithm file). But in my project not.

Thanks for download

lobi gravatar imagelobi ( 2013-11-01 16:49:40 -0600 )edit

This si youre inlcudes in jni .cpp file

include <jni.h>

include <opencv/cv.h>

include <opencv2/imgproc/imgproc.hpp>

include <opencv2/features2d/features2d.hpp>

include <android/log.h>

and I run ndk-build on your test project

that what I get slani@user:~/Downloads/testApp$ ../../code/android-ndk-r9/ndk-build Android NDK: WARNING: APP_PLATFORM android-18 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml

Compile++ thumb : testLibrary <= detect_jni.cpp SharedLibrary : libtestLibrary.so Install : libtestLibrary.so => libs/armeabi/libtestLibrary.so

and this is my includes in my jni .cpp file

include <jni.h>

include <opencv/cv.h>

include <opencv2/imgproc/imgproc.hpp>

include <opencv2/features2d/features2d.hpp>

and what I get

lobi gravatar imagelobi ( 2013-11-01 17:00:26 -0600 )edit

slani@user:~/code/androCV/RgbToHsv$ ../../android-ndk-r9/ndk-build Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 10 in ./AndroidManifest.xml

Compile++ thumb : testLibrary <= detect.cpp In file included from /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv/cv.h:64:0, from jni/detect.cpp:2: /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp:56:21: fatal error: algorithm: No such file or directory compilation terminated. make: * [obj/local/armeabi/objs/testLibrary/detect.o] Error 1

your and my Android.mk and Aplication.mk files are the same.

lobi gravatar imagelobi ( 2013-11-01 17:02:13 -0600 )edit

I find my mistake

my name of Application.mk file was Aplication.mk

f.... PPPPPPPPPPPPPPPPPPPPPPPPPPPP

Thomas THANKS for your help!!!!!!

lobi gravatar imagelobi ( 2013-11-01 19:52:23 -0600 )edit
0

answered 2013-11-06 10:17:34 -0600

leo gravatar image

Hi.i meat problem.like your app.but,my problem is that when use ndkto built, it not load libopencb.so , my Android. Mk are same with your.and I use you testapp ,andmeet this problem again. Please help me. thanks.

edit flag offensive delete link more

Comments

your error "description" is not very helpful

ThomasB gravatar imageThomasB ( 2013-11-08 07:43:28 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-10-29 17:12:21 -0600

Seen: 13,678 times

Last updated: Nov 06 '13