Eclipse can't include opencv2 header files - android

I've created an Android Application Project in Eclipse Juno, and after I've added native support to this project (Android Tools -> Add Native Support). So Eclipse has added in the project automatically a jni directory, within which a .cpp file and the file Android.mk.
Then I've build the project, without errors.
In order to use opencv for android libraries (2.4.5), I've added the path to the 'include' directory of these libraries in the project (Properties -> C/C++ General -> Path And Symbols -> Include Diretories). I've also set in the Eclipse Preferences -> NDK the correct path to the ndk directory in my pc, to make possible to execute ndk-build when I build the projects.
But, if i try to include in the .cpp file:
#include <opencv2/opencv.hpp>
The console show me this result:
12:24:25 **** Build of configuration Default for project ProvaVideoCapture ****
"C:\\Users\\Micaela\\Desktop\\Android\\android-ndk-r8e\\ndk-build.cmd" all
"Compile++ thumb : jniVideoCapture <= jniVideoCapture.cpp
jni/jniVideoCapture.cpp:4:30: fatal error: opencv2/opencv.hpp: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs/jniVideoCapture/jniVideoCapture.o] Error 1
12:24:26 Build Finished (took 282ms)
My Android.mk file is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jniVideoCapture
LOCAL_SRC_FILES := jniVideoCapture.cpp
include $(BUILD_SHARED_LIBRARY)
The Application.mk file that I've added manually (it has not been automatically added by Eclipse) is:
APP_ABI := all
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_PLATFORM := android-9
I don't know how to solve this problem, or what I've done wrong.
Could you help me?

Add path like below to your Android.mk file and check
include E:/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
Sample Android.mk for reference
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on
include E:/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
include $(OPENCV_MK_PATH)
LOCAL_MODULE := firstcv
LOCAL_SRC_FILES := first.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)

Related

How do I build the arcore camera_utility shared library in NDK-BUILD?

I'm trying to build the 'arcore camera utility' library in NDK_BUILD, here: https://github.com/google-ar/arcore-unity-sdk/tree/master/Assets/GoogleARCore/Examples/ComputerVision/Plugins/src
Using this guide: https://yeephycho.github.io/2016/10/20/How-to-Use-NDK-to-Build-A-Shared-Android_Native-Library/ I was at least able to get it to compile in a libarcore_camera_utility.so file. Not only that but it was actually recognized by my app on the phone and instead of getting a DLL missing error I got the error: "EntryPointNotFoundException: Unable to find an entry point named 'TextureReader_create' in 'arcore_camera_utility'." which means it at least found the file, now.
The filesize of the .so is only 6k so it seems like I'm not compiling it correctly as the already working 32bit version that comes with the package is 100k, based on this question it seems like I'm leaving something out?: Entry point not found, Android .so file
My Android.mk file is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := arcore_camera_utility_shared
LOCAL_C_INCLUDES += \
LOCAL_SRC_FILES := camera_utility.cc gl_utility.cc texture_reader.cc
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := arcore_camera_utility
LOCAL_WHOLE_STATIC_LIBRARIES := arcore_camera_utility_shared
include $(BUILD_SHARED_LIBRARY)
And my Application.mk file contains:
APP_ABI := arm64-v8a
APP_PLATFORM := android-24
APP_STL := c++_static
APP_BUILD_SCRIPT := ./jni/Android.mk
Am I building it in such a way as to leave the code out?
To compile arcore_camera_utility for the arm 64bit target-
1.) Create a new directory called 'arcorelibrary', then a subdirectory called 'jni'
2.) Download this zip: https://github.com/google-ar/arcore-unity-sdk/blob/master/Assets/GoogleARCore/Examples/ComputerVision/Plugins/src/arcore_camera_utility.zip
3.) get the three .cc files and the three .h files and place them in the jni directory
4.) Create a file called 'Android.mk' and place it in the jni directory, with the following contents:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= arcore_camera_utility_static
LOCAL_SRC_FILES:= camera_utility.cc gl_utility.cc texture_reader.cc
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_EXPORT_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lGLESv3
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := arcore_camera_utility
LOCAL_WHOLE_STATIC_LIBRARIES := arcore_camera_utility_static
include $(BUILD_SHARED_LIBRARY)
5.) Create a file called 'Application.mk' and place it in the jni directory, with the following contents:
APP_ABI := arm64-v8a
APP_PLATFORM := android-24
APP_STL := c++_static
APP_BUILD_SCRIPT := ./jni/Android.mk
6.) Download Android NDK and unzip somewhere (The version you need depends on which Unity version you're using) https://developer.android.com/ndk/downloads/older_releases.html
7.) Open a terminal or powershell, go to the root directory (arcorelibrary) of your project
8.) Create a path to where ever you unzipped Android NDK (Powershell example):
$env:Path += ";C:\[where-ever-you-unzipped]\android-ndk-r13b-windows-x86_64\android-ndk-r13b"
9.) Run:
ndk-build.cmd

Compile C++ native activity with NDK

I create Android native activity project based on "native-activity" project in NDK. In this project android_main function is implemented in main.c file and it compiles and run without any issues.
Now I wants to implement some C++ routines in this file and to do that, as a first step I change main.c file to main.cpp and change LOCAL_SRC_FILES entry in Android.mk to main.cpp.
After this change I got following error at the compilation:
make.exe: *** No rule to make target `jni/main.c', needed by `obj/local/arm64-v8a/objs/native-activity/main.o'. Stop.
Also Android.mk file in this project contain following entries:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native-activity
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
What was the possible cause for this error?
Delete your obj directory from workspace and rebuild. Sometimes eclipse clean is not working and failed to delete obj files.

How to build Android NDK cocos2d-x project from within Eclipse?

I set up an Android project that uses cocos2d-x. Now I want to build the project in Eclipse but I get the build error
Android NDK: jni/Android.mk: Cannot find module with tag '.' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
Which means that my library was not built.
I'm using the Android.mk file as in the templates of cocos2d:
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := my-library
LOCAL_C_INCLUDES := /home/me/cocos2d-x-3.4 \
/home/me/cocos2d-x-3.4/extensions \
/home/me/cocos2d-x-3.4/cocos/editor-support
LOCAL_SRC_FILES := main.cpp \
AppDelegate.cpp
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := cocos2dx_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
The ndk path is set correctly for the project. How can I build my cocos2d-x project correctly when using Eclipse?
The following procedure worked for me:
Goto Eclipse/ADT preferences.
Then C/C++ -> Build -> Envionment
Click on Add.
Put NDK_ROOT in Name and path of NDK under Value.
Now try to
build it from eclipse, if it doesn't work, then Repeat the procedure
and this time put NDK_MODULE_PATH under Name.

Not able to build Android NDK project fatal error: android/configuration.h: No such file or directory compilation terminated

I am building a complete native app in using Android NDK, when I try to build the app I am getting the following error:
D:/Softwares/android-ndk-r9c/sources/android/native_app_glue/android_native_app_glue.h:25:35: fatal error: android/configuration.h: No such file or directory compilation terminated.
I am not getting why this error is coming. I have created an Android.mk file with following content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mynativeactivity
LOCAL_SRC_FILES := Log.cpp Main.cpp EventLoop.cpp
LOCAL_LDLIBS := -llog -landroid
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Also, in the project properties I have added following Paths & Symbols
D:/Softwares/android-ndk-r9c/platforms/android-9/arch-arm/usr/include
D:/Softwares/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.8/include
D:/Softwares/android-ndk-r9c/sources/android/native_app_glue
Can anyone suggest what am I doing wrong ?
LOCAL_LDLIBS := -landroid is the problem.
The system is expecting the configuration.h file, as simple as that.
Why do you mean by project properties ? in eclipse ? .
ndk-build would not pick your ecplise project properties.
Please add Application.mk file and mention the APP_PLATFORM := android-9 ( not sure if it should solve the problem).Otherwise , add the include path LOCAL_C_INCLUDES in your android.mk file.

android ndk no rule to make target

I realise this question has been asked before but no answers have been able to solve my problem.
I'm trying to build a sample android app provided with NDK which has the following Android.mk file:
LOCAL_PATH := $(call my-dir)
MY_PATH := $(LOCAL_PATH)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_PATH := $(MY_PATH)
LOCAL_MODULE := native-activity
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
When I build my project I get the follow error:
**** Build of configuration Default for project NativeActivity ****
/Users/Jono/Documents/Development/Android Development/android-ndk-r9c/ndk-build all
usage: dirname path
make: /Users/Jono/build/core/build-local.mk: No such file or directory
make: *** No rule to make target `/Users/Jono/build/core/build-local.mk'. Stop.
**** Build Finished ****
The problem is that it is looking for build files in my root directory, but I'm not really sure what its doing, what files it looking for, where it should be looking and then what I should do to fix it.
You should not use space in your path to NDK. Change the folder name "Android Development" to something with no white space, i.e. "AndroidDevelopment".
NDK may get very unhappy when the directory names have spaces, as your Android Development. Simply rename the directory to Android_Development, and don't forget to update the ADT preferences.

Categories

Resources