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.
Related
I'm new to Android NDK, and I'm currently trying to build a RTMP C client for Android (and later iOS). Currently, I'm running into an issue where the application crashes as soon as I try to load my library:
static {
System.loadLibrary("test");
}
The exception I get is
java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "librtmp.so.1" needed by "libtest.so"; caused by library "librtmp.so.1" not found
I'm honestly completely lost. ndk-build doesn't return any errors:
[armeabi] Prebuilt : rtmp.so <= jni/rtmp/
[armeabi] Install : rtmp.so => libs/armeabi/rtmp.so
[armeabi] Compile thumb : test <= RTMPClient.c
[armeabi] SharedLibrary : libtest.so
[armeabi] Install : libtest.so => libs/armeabi/libtest.so
I've tried loading in the rtmp librarary via System.loadLibrary("rtmp"), but no dice.
Android.mk
LOCAL_PATH:= $(call my-dir)
LIBS_PATH := libs/$(TARGET_ARCH_ABI)
include $(CLEAR_VARS)
LOCAL_MODULE := rtmp
LOCAL_SRC_FILES := rtmp/rtmp.so
LOCAL_C_INCLUDES := rtmp/
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := RTMPClient.c
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES += rtmp
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_PLATFORM:=android-19
My RTMPClient.c uses some structs and functions from rtmp like so:
#include <rtmp/rtmp.h>
I'm not sure where librtmp.so.1 is coming from, but I also found it in my libtest.so with arm-linux-andrioideabi-readelf:
0x00000001 (NEEDED) Shared library: [librtmp.so.1]
Any ideas on how I can fix this?
EDIT: I got the rtmp.so file from here. I was sent there from the KODI librtmp update page
I ended up throwing out my rtmp.so file, and instead grabbed the jni files from rtmpdump-android. After putting those file in, changing my android.mk file to:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES += \
librtmp/amf.c \
librtmp/hashswf.c \
librtmp/log.c \
librtmp/parseurl.c \
librtmp/rtmp.c
LOCAL_CFLAGS := -D__STDC_CONSTANT_MACROS -DNO_CRYPTO
LOCAL_LDLIBS := -llog
LOCAL_MODULE := librtmp
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := dump
LOCAL_CFLAGS := -DRTMPDUMP_VERSION=\"v2.4\"
LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := dump/rtmpdump.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../librtmp
LOCAL_C_INCLUDES += dump/rtmpdump.h
LOCAL_STATIC_LIBRARIES := librtmp
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := nelly.c nelly_tables.c RTMPClient.c
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES += dump
include $(BUILD_SHARED_LIBRARY)
And changing my RTMPClient.c file to include #include "librtmp/rtmp.h" instead of #include <rtmp/rtmp.h>, the file compiled and ran on my device without any issues.
I'm trying to configure Eclipse with NDK. During building (clean, build - wathever) the project, I have this:
13:09:42 **** Clean-only build of configuration Default for project Project ****
"D:\\android\\android-ndk-r10e\\ndk-build.cmd" clean
Access denied - JNI/../../../../PROJECT/SRC
File not found - -NAME
File not found - -PRINTF
File not found - ../../../../PROJECT/SRC/%P \N
Android NDK: WARNING:jni/Android.mk:project: LOCAL_LDLIBS is always ignored for static libraries
[armeabi-v7a] Clean : bullet [armeabi-v7a]
[armeabi-v7a] Clean : freetype [armeabi-v7a]
[armeabi-v7a] Clean : openal [armeabi-v7a]
[armeabi-v7a] Clean : stlport_shared [armeabi-v7a]
[armeabi-v7a] Clean : stlport_static [armeabi-v7a]
[armeabi-v7a] Clean : project [armeabi-v7a]
[armeabi-v7a] Clean : vpx [armeabi-v7a]
13:09:43 Build Finished (took 1s.168ms)
And my android.mk:
LOCAL_PATH:= $(call my-dir)
TARGET_PLATFORM := android-9
include $(CLEAR_VARS)
#include $(LOCAL_PATH)/bullet.mk
LOCAL_MODULE := bullet
LOCAL_SRC_FILES = ../../../../Project/lib_android/lib/$(TARGET_ARCH_ABI)/libbullet.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE := libvpx
LOCAL_SRC_FILES = ../../../../Project/lib_android/lib/$(TARGET_ARCH_ABI)/libvpx.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := openal
LOCAL_SRC_FILES = ../../../../Project/lib_android/lib/$(TARGET_ARCH_ABI)/libopenal.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := freetype
LOCAL_SRC_FILES = ../../../../Project/lib_android/lib/$(TARGET_ARCH_ABI)/libfreetype.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := project
TARGET_PLATFORM := android-9
OPENGLES_LIB := -lGLESv2
OPENGLES_DEF := -DUSE_OPENGL_ES_2_0
LOCAL_SHARED_LIBRARIES := openal libvpx freetype libbullet
#LOCAL_ARM_MODE := arm
LOCAL_MODULE_FILENAME := libproject
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../../../Project/src/ \
$(LOCAL_PATH)/../../../../Project/inc/bullet \
$(LOCAL_PATH)/../../../../Project/inc/ \
$(LOCAL_PATH)/../../../../Project/inc/freetype/include \
$(LOCAL_PATH)/../../../../Project/inc_android/ \
$(LOCAL_PATH)/../../../../Project/inc_android/openal/include \
$(LOCAL_PATH)/../../../../Project/inc_android/openal/OpenAL32/Include \
$(LOCAL_PATH)/../../../src \
#$(error "$(LOCAL_PATH)/../../../../Project/src/")
LOCAL_CPPFLAGS := $(LOCAL_CPP_INCLUDES:%=-I%) -rdynamic -std=c++11
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -ldl -lm -llog \
-lGLESv2 -ldl -llog -lEGL -Wl,-s
cppfiles := $(shell find $(LOCAL_PATH)/../../../../Project/src -name "*.cpp" -printf "../../../../Project/src/%%P \n")
LOCAL_SRC_FILES := $(cppfiles)
include $(BUILD_STATIC_LIBRARY)
I've been trying to reinstall everything, configure permissions, moving projects, NDK, SDK and I have nothing. I have no idea what I should do. I'm stuck. What am I missing?
I changed this:
cppfiles := $(shell find $(LOCAL_PATH)/../../../../Project/src -name "*.cpp" -printf "../../../../Project/src/%%P \n")
LOCAL_SRC_FILES := $(cppfiles)
to this:
cppfiles := $(wildcard $(LOCAL_PATH)/../../../../Project/src/*.cpp)
LOCAL_SRC_FILES := $(cppfiles:$(LOCAL_PATH)/%=%)
And it works. If you want to attach files located in subdirectories, you need to add symbol ** like
src/**/*.cpp
I'm getting this warning while running $ANDROID_NDK_ROOT/ndk-build. The Android.mk is below.
$ $ANDROID_NDK_ROOT/ndk-build
WARNING:/Users/jwalton/Android-CryptoPP/jni/Android.mk:prng:
non-system libraries in linker flags: -lcryptopp -lstlport_shared
This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
current module
...
However, when I follow the instructions and remove -lcryptopp -lstlport_shared from LOCAL_LDLIBS, then I get link errors related to symbols from libstlport_shared.so. A sample of the errors are shown below after the Android.mk file.
How, exactly, does ndk-build want Android.mk set up?
Why do I have to add $(STLPORT_INCL) to LOCAL_C_INCLUDES, and $(STLPORT_LIB) to LOCAL_LDFLAGS? Why does APP_STL := stlport_shared not setup the STL correctly out of the box?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
TARGET_ARCH_ABI := armeabi
TARGET_ABI := android-9-armeabi
CRYPTOPP_INCL := /usr/local/cryptopp-android-9/include
CRYPTOPP_LIB := /usr/local/cryptopp-android-9/lib
STLPORT_INCL := /opt/android-ndk-r9/sources/cxx-stl/stlport/stlport
STLPORT_LIB := /opt/android-ndk-r9/sources/cxx-stl/stlport/libs/armeabi
APP_STL := stlport_shared
APP_MODULES := stlport_shared cryptopp
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_C_INCLUDES := $(CRYPTOPP_INCL) $(CRYPTOPP_INCL)/cryptopp $(STLPORT_INCL)
LOCAL_LDFLAGS := -L $(CRYPTOPP_LIB) -L $(STLPORT_LIB)
LOCAL_LDLIBS := -lcryptopp -lstlport_shared -llog -landroid
# LOCAL_LDLIBS := -llog -landroid
# LOCAL_SHARED_LIBRARIES := -lcryptopp -lstlport_shared
LOCAL_MODULE := prng
LOCAL_SRC_FILES := libprng.cpp
include $(BUILD_SHARED_LIBRARY)
Here is a sample of the error when trying to follow the advice by removing my local libraries from LOCAL_LDLIBS:
$ $ANDROID_NDK_ROOT/ndk-build
Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 9 in /Users/jwalton/Android-CryptoPP/AndroidManifest.xml
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : prng <= libprng.cpp
SharedLibrary : libprng.so
/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/jwalton/Android-CryptoPP/obj/local/armeabi/objs-debug/prng/libprng.o: in function std::__node_alloc::allocate(unsigned int&):/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/stl/_alloc.h:158: error: undefined reference to 'std::__node_alloc::_M_allocate(unsigned int&)'
/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/jwalton/Android-CryptoPP/obj/local/armeabi/objs-debug/prng/libprng.o: in function std::__node_alloc::deallocate(void*, unsigned int):/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/stl/_alloc.h:161: error: undefined reference to 'std::__node_alloc::_M_deallocate(void*, unsigned int)'
/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/jwalton/Android-CryptoPP/obj/local/armeabi/objs-debug/prng/libprng.o: in function std::ios_base::_M_check_exception_mask():/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/stl/_ios_base.h:193: error: undefined reference to 'std::ios_base::_M_throw_failure()'
...
I interpret the "non-system libraries in linker flags" message as a warning that you're not using the default system libraries (in usr/lib) which may be perfectly fine, but which could also lead to errors (incompatibility between different libraries versions). Whether this warning bugs you is completely up to you.
Then, about the way you tried to solve it, I think you're using wrongly the LOCAL_SHARED_LIBRARIES variable of the NDK.
I paste here a sample from one of my Android.mk file which uses Assimp
#------------------------------------------------------------------ Assimp
include $(CLEAR_VARS)
LOCAL_MODULE := Assimp
LOCAL_EXPORT_C_INCLUDES := $(GENERATED_INCLUDE_PATH)/assimp/include
LOCAL_SRC_FILES := $(GENERATED_PATH)/assimp/lib/libassimp.a
include $(PREBUILT_STATIC_LIBRARY)
...
LOCAL_STATIC_LIBRARIES := \
Assimp \
<Your other libs here>
As you can see, I declare a LOCAL_MODULE with a custom name, set up a few variables and then include the PREBUILT_STATIC_LIBRARY script which tells the NDK to use this lib.
Then in LOCAL_STATIC_LIBRARIES I list the libraries I use with their module name, not as if this was a linker flag like you're doing here.
In your case, I believe you should do the following, for example for the stl
include $(CLEAR_VARS)
LOCAL_MODULE := STLPortShared
LOCAL_EXPORT_C_INCLUDES := <path to stlport includes>
LOCAL_SRC_FILES := <path to stlport library>
include $(PREBUILT_SHARED_LIBRARY)
...
#Notice the name, identical to the one specified for LOCAL_MODULE
LOCAL_SHARED_LIBRARIES = STLPortShared
I think this should do it. Of course, repeat the process for each libs that causes trouble, and don't forget the include(CLEAR_VARS) between each lib specification.
As specified in this answer, I downloaded libjpeg 8d from github and placed it in a folder {ANDROID_APP}/jni/libjpeg. This library has it's own Android.mk, so I tried to include it at the end of my {ANDROID_APP}/jni/Android.mk this way :
include $(LOCAL_PATH)/libjpeg/Android.mk
Note : I'm using the latest version of android NDK (r8c)
After running ndk-build, I still get this error :
ANDROID_APP/jni/libfoo/foo_analysis.c:36:21: fatal error: jpeglib.h: No such file or directory
This is the structure of my global Android.mk :
LOCAL_PATH := $(call my-dir)
# libFoo
include $(CLEAR_VARS)
LOCAL_MODULE := libfoo
LOCAL_MODULE_FILENAME := libfoo
LOCAL_SRC_FILES := libfoo/foo.c libfoo/foo_analysis.c libfoo/foo_extract.c
LOCAL_STATIC_LIBRARIES := libbmp # declared previously but not shown in this example
LOCAL_CFLAGS = ${FLAGS}
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libfoo
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)
# libBar
include $(CLEAR_VARS)
LOCAL_MODULE := libbar
LOCAL_MODULE_FILENAME := libbar
LOCAL_SRC_FILES := bar/bar.c
LOCAL_STATIC_LIBRARIES := libfoo
LOCAL_CFLAGS = ${FLAGS}
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)
# callbar
LOCAL_MODULE := libcallbar
LOCAL_MODULE_FILENAME := libcallbar
LOCAL_SRC_FILES := com_androidapp_nativeC_callbar.c
LOCAL_STATIC_LIBRARIES := libbar
LOCAL_CFLAGS = ${FLAGS}
include $(BUILD_SHARED_LIBRARY)
#libjpeg
include $(LOCAL_PATH)/libjpeg/Android.mk
I tried to use LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libfoo $(LOCAL_PATH)/libjpeg
and LOCAL_C_INCLUDES := $(LOCAL_PATH)/libjpeg in the libFoo module, but I still get the same error.
Just looked at Android.mk in jpeg8d-master folder and seems to be it has nothing.
I was trying to compile library directly according to STANDALONE-TOOLCHAIN.HTML
I do next: $export NDKROOT=/home/alex/tools/android-ndk-r8c (where is your NDK) $export SYSROOT=$NDKROOT/platforms/android-9/arch-arm (or any other android platform)
but files from jpeg8d-master have windows \r symbols and I deleted config.guess, config.sub, depcomp than use $automake -a command. And replace ltmain.sh from glib-2.34.0
than $./configure CC="$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=$SYSROOT" --host=arm-linux-androideabi $make
next try prebuilts feature NDK - How to use a generated .so library in another project and NDK/PREBUILTS.HTML
I use this AES library (in C language),
http://gladman.plushost.co.uk/oldsite/AES/aes-src-16-04-07.zip
I follow this page and use the commds mentioned to compile libaes.a,
http://forums.devshed.com/c-programming-42/aes-encrypt-decrypt-in-c-687368.html
gcc -c -O2 -fomit-frame-pointer aescrypt.c aeskey.c aestab.c aes_modes.c
ar rcs libaes.a *.o
I can compile and run my program using the libaes.a without problem.
However if use ndk-build to compile my program (indeed modified a little),
I always get this error message and fail to compile...
"...member aes_modes.o in archive is not an object..."
what's wrong with that file?
Or what's wrong with the process?
my Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libaes
LOCAL_SRC_FILES := libaes.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_C_INCLUDES :=\
/android-ndk-r6b/platforms/android-8/arch-arm/usr/include\
/android-ndk-r6b/samples/hello-jni/jni/libaes
LOCAL_WHOLE_STATIC_LIBRARIES := libaes
include $(BUILD_SHARED_LIBRARY)
I've a feeling that you compiled aes with native tools (x86) and using it as prebuild library. I've tried this Android.mk and it works:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := aes
LOCAL_SRC_FILES := aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := jni/aes
LOCAL_STATIC_LIBRARIES := aes
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
Just unzip aes-src-16-04-07.zip into jni/aes. I think it is better to use ndk build system because it can set all necesary options.
And hello-jni.c (just in case):
#include <aes.h>
void test() {
aes_init();
}