I need to use minizip with zlib in android ndk.
My jni/MyApp/Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyApp
LOCAL_SRC_FILES := MyApp.cpp
LOCAL_LDLIBS := -lz
include $(BUILD_SHARED_LIBRARY)
My jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
My jni/MyApp/MyApp.cpp
#include <zlib.h>
#include "minizip/unzip.h" #it's in jni/MyApp/minizip/unzip.h
void unzip(char* file, char* folder) {
unzFile zip = unzOpen(file);
}
My jni/Application.mk
APP_MODULES := MyApp
APP_STL := gnustl_static
But, when I compile it:
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
SharedLibrary : libMyApp.so
C:/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
Z:/workspace/MyApp/obj/local/armeabi/objs-debug/MyApp/MyApp.o: in function unzip(char*, char*):Z:/workspace/MyApp/jni/MyApp/MyApp.cpp:5: error: undefined reference to 'unzOpen' collect2: ld returned 1 exit status make: *** [Z:/workspace/MyApp/obj/local/armeabi/libMyApp.so] Error 1
If I remove the line "unzFile zip = unzOpen(file);" it works
Can you help me? :D
Thanks!
Oh...
I forgot to add the c files in LOCAL_SRC_FILES :D
Related
I am trying to import a module into my project.
Android.mk in module:
LOCAL_PATH := $(call my-dir)
include $(CEAR_VARS)
LOCAL_MODULE := fromhere1
LOCAL_MODULE_FILENAME := fromhere1
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfromhere.so
include $(PREBUILT_SHARED_LIBRARY)
libfromhere.so is built by ndk-build
Android.mk in my project:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_MODULE_FILENAME := libnative
LOCAL_SRC_FILES := native.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/
LOCAL_SHARED_LIBRARIES := fromhere1
include $(BUILD_SHARED_LIBRARY)
$(call import-module,module)
When I run ndk-build, I get error
[arm64-v8a] Compile : native <= native.c
make: Circular /home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so <- /home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so dependency dropped.
[arm64-v8a] SharedLibrary : libnative.so
aarch64-linux-android-g++: error: /home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so: No such file or directory
make: *** [/home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so] Error 1.
I don't understand why that circular dependency is arising.
I followed proper syntax.
After include $(PREBUILT_SHARED_LIBRARY) you have to clear the variable may be you are again prebuilding another library... this stuff solved my issue :)
LOCAL_PATH := $(call my-dir)
include $(CEAR_VARS)
LOCAL_MODULE := fromhere1
LOCAL_MODULE_FILENAME := fromhere1
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfromhere.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CEAR_VARS)
LOCAL_MODULE := fromhere2
LOCAL_MODULE_FILENAME := fromhere2
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfromhere2.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CEAR_VARS)
My mistake is the value of LOCAL_MODULE_FILENAME. It must be libfromhere1 instead of fromhere1.
ndk just puts .so suffix to the given name but it won't put lib prefix.
Always it is better to give name by yourself than letting ndk name it for you.
But I didn't understand why circular dependency arose because of that.
I followed the instructions from here and added OpenCV successfully. But I've been trying to add tesseract to the Android.mk as well, for a few days now, and haven't been able to do it.
I have an android.cpp that uses tesseract so I have to include the dependency in my Android.mk . I found this post that had almost the exact problem and he solved it importing libtess.so and liblept.so files into Android.mk, but didn't explain how to do that, so I looked and found this post that shows how to link prebuilt libraries. So based on that I tried this Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := liblept
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk
LOCAL_MODULE := run_detection
LOCAL_SHARED_LIBRARIES := libtess
LOCAL_SRC_FILES := text_detect.cpp android.cpp
LOCAL_LDLIBS += -landroid -llog -ldl
include $(BUILD_SHARED_LIBRARY)
And got this output:
[armeabi-v7a] Prebuilt : liblept.so <= src/main/jni/../libs/armeabi-v7a/
[armeabi-v7a] Install : liblept.so => src/main/jniLibs/armeabi-v7a/liblept.so
[armeabi-v7a] Compile++ thumb: run_detection <= text_detect.cpp
In file included from src/main/jni/text_detect.h:4:0,
from src/main/jni/text_detect.cpp:10:
src/main/jni/../../../../tess-two/jni/com_googlecode_tesseract_android/src/api/baseapi.h:32:22: fatal error: platform.h: No such file or directory
#include "platform.h"
^
compilation terminated.
So I guess is not linking libtess correctly, and if you look closely, it doesn't ever install libtess.so, it looks like it installs liblept.so, and then jumps to text_detect.cpp, ignoring this part:
include $(CLEAR_VARS)
LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)
So I tried to force it to install liblept and libtess completely before proceeding by putting it in different files. So I put the last part of the file in a different Android.mk in another folder and tried include $(call all-subdir-makefiles), and then it installs libtess and liblept completely, but ignores the call all-subdir-makefiles.
new jni folder structure:
Android.mk
Application.mk
text_detect/
Android.mk
android.cpp
text_detect.cpp
text_detect.h
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := liblept
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)
include $(call all-subdir-makefiles)
textdetect/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk
LOCAL_MODULE := run_detection
LOCAL_SHARED_LIBRARIES := libtess
LOCAL_SRC_FILES := text_detect.cpp android.cpp
LOCAL_LDLIBS += -landroid -llog -ldl
include $(BUILD_SHARED_LIBRARY)
And this is the output:
[armeabi-v7a] Prebuilt : liblept.so <= src/main/jni/../libs/armeabi-v7a/
[armeabi-v7a] Install : liblept.so => src/main/jniLibs/armeabi-v7a/liblept.so
[armeabi-v7a] Prebuilt : libtess.so <= src/main/jni/../libs/armeabi-v7a/
[armeabi-v7a] Install : libtess.so => src/main/jniLibs/armeabi-v7a/libtess.so
[armeabi] Prebuilt : liblept.so <= src/main/jni/../libs/armeabi/
[armeabi] Install : liblept.so => src/main/jniLibs/armeabi/liblept.so
[armeabi] Prebuilt : libtess.so <= src/main/jni/../libs/armeabi/
[armeabi] Install : libtess.so => src/main/jniLibs/armeabi/libtess.so
[mips] Prebuilt : liblept.so <= src/main/jni/../libs/mips/
[mips] Install : liblept.so => src/main/jniLibs/mips/liblept.so
[mips] Prebuilt : libtess.so <= src/main/jni/../libs/mips/
[mips] Install : libtess.so => src/main/jniLibs/mips/libtess.so
[x86] Prebuilt : liblept.so <= src/main/jni/../libs/x86/
[x86] Install : liblept.so => src/main/jniLibs/x86/liblept.so
[x86] Prebuilt : libtess.so <= src/main/jni/../libs/x86/
[x86] Install : libtess.so => src/main/jniLibs/x86/libtess.so
As you see it installs everything from the first Android.mk perfectly, but it never runs textdetect/Android.mk
So, what I'm I doing wrong? How can I achieve this task that seems so simple? Is there an easier way?
EDIT:
After #ph0b response I went back to my first setup and added the same LOCAL_EXPORT_C_INCLUDES as the original Makefiles (with a couple of variations adapting it to my paths), and that solved it. It couldn't find platform.h because it didn't know where to look for it.
Now, after I did this change I had a different error No such file or directory #include "com_googlecode_tesseract_android/src/api/baseapi.h" and I thought this was because it didn't compile tesseract before run_detection that depends on it. Well that wasn't the problem, it still compiles run_detection before tesseract but that wasn't the issue, it was so much simpler and I feel so stupid for having spent so much time on this error. The problem was it didn't find com_googlecode_tesseract_android/src/api/baseapi.h because I didn't provide the path for that either, so I copied com_googlecode_tesseract_android and com_googlecode_leptonica_android from tess-two and added $(LOCAL_PATH) to LOCAL_EXPORT_C_INCLUDES. This is my final solution:
jni folder structure:
Android.mk
Application.mk
text_detect.cpp
android.cpp
text_detect.h
com_googlecode_leptonica_android
com_googlecode_tesseract_android
Android.mk
LOCAL_PATH := $(call my-dir)
#leptonica
LEPTONICA_LOCAL := $(LOCAL_PATH)/com_googlecode_leptonica_android
LEPTONICA_PATH := $(LEPTONICA_LOCAL)/src
include $(CLEAR_VARS)
LOCAL_MODULE := liblept
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES := \
$(LEPTONICA_LOCAL) \
$(LEPTONICA_PATH)/src
include $(PREBUILT_SHARED_LIBRARY)
#tesseract
TESSERACT_LOCAL := $(LOCAL_PATH)/com_googlecode_tesseract_android
TESSERACT_PATH := $(TESSERACT_LOCAL)/src
include $(CLEAR_VARS)
LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH) \
$(TESSERACT_PATH)/api \
$(TESSERACT_PATH)/ccmain \
$(TESSERACT_PATH)/ccstruct \
$(TESSERACT_PATH)/ccutil \
$(TESSERACT_PATH)/classify \
$(TESSERACT_PATH)/cube \
$(TESSERACT_PATH)/cutil \
$(TESSERACT_PATH)/dict \
$(TESSERACT_PATH)/opencl \
$(TESSERACT_PATH)/neural_networks/runtime \
$(TESSERACT_PATH)/textord \
$(TESSERACT_PATH)/viewer \
$(TESSERACT_PATH)/wordrec \
$(LEPTONICA_PATH)/src \
$(TESSERACT_LOCAL)
LOCAL_SHARED_LIBRARIES := liblept
include $(PREBUILT_SHARED_LIBRARY)
#opencv
include $(CLEAR_VARS)
OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk
LOCAL_MODULE := run_detection
LOCAL_SRC_FILES := text_detect.cpp android.cpp
LOCAL_LDLIBS += -landroid -llog -ldl
LOCAL_SHARED_LIBRARIES += libtess liblept
include $(BUILD_SHARED_LIBRARY)
Your latest setup is failing in a weird way, ndk-build should at least try to compile your module. Maybe there is a bug in all-subdir-makefiles when there are ndk modules defined before it, and it doesn't find your module's Android.mk. You can try having only include $(call all-subdir-makefiles) inside your top level Android.mk.
Anyway, I think you should go back to your first setup, with your module directly in the jni root folder. Then, your main issue is the proper declaration of includes paths. tess-two/jni doesn't contain any headers ? They're in tess-two/jni/com_googlecode_*_android/src/*. That means you need to list these in your module declarations, by giving all the absolute paths to LOCAL_EXPORT_C_INCLUDES variables (like from the original Makefiles: https://github.com/rmtheis/tess-two/blob/master/tess-two/jni/com_googlecode_tesseract_android/Android.mk#L33)
You also need to add the dependency on liblept for libtess: LOCAL_SHARED_LIBRARIES := liblept inside libtess library declaration.
If it still fails, there is also another possibility: instead of redefining libtess and liblept modules using the generated .so files, you can directly include tess-two/jni/Android.mk and use the same Application.mk than tess-two (copy `tess-two/jni/Application.mk). It will already properly define libtess and liblept modules.
I'm trying to develope a native code with OpenCV using IntelliJ IDEA 13.1.4. When I try to ndk-build the code provided in mixedprocessing sample, I have this error:
[armeabi-v7a] Compile++ thumb: com_sample_jniLib <= com_sample_jniLib.cpp
[armeabi-v7a] SharedLibrary : libcom_sample_jniLib.so
D:/Workspace/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lopencv_java
make.exe: *** [obj/local/armeabi-v7a/libcom_voxar_tracker_TrackerLib.so] Error 1
D:\Workspace\android-ndk-r10\sources\cxx-stl\stlport\stlport
Basically, he can't find -lopencv_java.
Here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include jni/opencv/OpenCV.mk
LOCAL_SRC_FILES := com_voxar_tracker_TrackerLib.cpp
LOCAL_MODULE := com_voxar_tracker_TrackerLib
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
And my Application.mk:
APP_STL := stlport_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
As I told before, I'm using IntelliJ IDEA 13.1.4, OpenCV 2.4.9 and Android NDK r10 32-bit on Windows 8.1. Does anybody have any idea of what that could be?
You seem to have forgot OPENCV_INSTALL_MODULES:=on in your Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
include jni/opencv/OpenCV.mk
LOCAL_SRC_FILES := com_voxar_tracker_TrackerLib.cpp
LOCAL_MODULE := com_voxar_tracker_TrackerLib
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
I have some header files in include folder.
Here is the Android.mk file contents.
include $(call all-subdir-makefiles)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := fpdfembedsdk
LOCAL_SRC_FILES := FoxitEMBSDK_EMBJavaSupport.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_LDLIBS := -llog -g -L. -ljnigraphics
LOCAL_LDLIBS += libfpdfemb_android.a
include $(BUILD_SHARED_LIBRARY)
I am getting the following error.
$ /cygdrive/c/Android/android-ndk/ndk-build
Compile++ thumb : fpdfembedsdk <= FoxitEMBSDK_EMBJavaSupport.cpp
jni/FoxitEMBSDK_EMBJavaSupport.cpp:9:21: fatal error: fs_base.h: No such file or directory
compilation terminated.
/cygdrive/c/Android/android-ndk/build/core/build-binary.mk:255: recipe for target `obj/local/armeabi/objs/fpdfembedsdk/FoxitEMBSDK_EMBJavaSupport.o' failed
make: *** [obj/local/armeabi/objs/fpdfembedsdk/FoxitEMBSDK_EMBJavaSupport.o] Error 1
can anybody pls help me?
LOCAL_C_INCLUDES := $(LOCAL_PATH)
Check that. I guess you pass the wrong path. Are you sure all headers are there?
I am trying to use a pre built library within my project...its name is libfreeimage.so...
I am not able to build it properly using the NDK-build....
The error log has been pasted here...
please help me in this regard...
flock#QS57:~/Desktop/android-imagefilter-ndk$ /home/flock/ANDROID/android-ndk-r8/ndk-build
Prebuilt : libfreeimage.so <= jni/
Install : libfreeimage.so => libs/armeabi/libfreeimage.so
/home/flock/ANDROID/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-strip: Unable to recognise the format of the input file `./libs/armeabi/libfreeimage.so'
make: *** [libs/armeabi/libfreeimage.so] Error 1
make: *** Deleting file libs/armeabi/libfreeimage.so
flock#QS57:~/Desktop/android-imagefilter-ndk$
My android.mk file-
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libfreeimage
LOCAL_SRC_FILES := libfreeimage.a
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := imageprocessing
LOCAL_SRC_FILES := imageprocessing.c
LOCAL_SHARED_LIBRARIES := libfreeimage
LOCAL_LDLIBS := -lm -llog -ljnigraphics
include $(BUILD_SHARED_LIBRARY)
You need to use
include ($BUILD_STATIC_LIBRARY)
instead of
include ($BUILD_SHARED_LIBRARY)
This will give you the desired .a file, not the .so.