this is my project situation: I compiled ffmpeg in windows using this tutorial and I imported the ffmpeg folder (with inside libffmpeg.so file) generated inside my android project (under jni folder).
In my project I have a jni_part.cpp where I inserted my jni function to operate with opencv.
In my Android.mk I'm using the code below to import opencv and compile the jni_part.cpp
include $(CLEAR_VARS)
include ../../sdk/native/jni/OpenCV.mk
LOCAL_MODULE := mixed_sample
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS += -llog -ldl
LOCAL_SHARED_LIBRARY := ffmpeg-prebuilt
include $(BUILD_SHARED_LIBRARY)
But what code I should use to import also ffmpeg? I tried to use this code:
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg-prebuilt
LOCAL_SRC_FILES := ffmpeg-0.8/android/armv7-a/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := ffmpeg-0.8/android/armv7-a/include/
LOCAL_EXPORT_LDLIBS := ffmpeg-0.8/android/armv7-a/libffmpeg.so
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)
but if from my jni_part.cpp code I try to include some ffmpeg files/libraries "#include <libavutil/avstring.h>" I get this error:
**** Build of configuration Default for project OpenCV Tutorial 4 - Mix Java+Native OpenCV ****
C:\android-ndk-r8c\ndk-build.cmd
Prebuilt : libffmpeg.so <= jni/ffmpeg-0.8/android/armv7-a/
Install : libffmpeg.so => libs/armeabi-v7a/libffmpeg.so
"Compile++ thumb : mixed_sample <= jni_part.cpp
jni/jni_part.cpp:24:32: fatal error: libavutil/avstring.h: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o] Error 1
**** Build Finished ****
Someone could help me please? I need to do this to include ffmpeg codec with the hope to use the function cvCaptureFromAVi...
Thanks in advance
Related
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.
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.
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)
i try to use freetype lib in my project with cocos2d-x. I built freetype and added to the project(like here http://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Android_NDK#FreeType ). In xcode it builds without errors. Now I trying to use it on android. I made make file in freetype dir:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := freetype
LOCAL_SRC_FILES := lib/libfreetype.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/include/freetype2
include $(PREBUILT_STATIC_LIBRARY)
and added to main makefile
LOCAL_STATIC_LIBRARIES := freetype curl_static_prebuilt
...
$(call import-module,freetype)
during linking has the error: libfreetype.a: file format not recognized; treating as linker script
Prebuilt : libfreetype.a <=
/Users/user/Development/Slots/Slots_Android/lib/freetype/lib/
SharedLibrary : libgame.so
/Users/user/Development/android_ndk_r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld:./obj/local/armeabi/libfreetype.a:
file format not recognized; treating as linker script
/Users/user/Development/android_ndk_r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld:./obj/local/armeabi/libfreetype.a:1:
syntax error collect2: ld returned 1 exit status
How to fix it?
I am planning to user static Linux .a library into android.
I have created static .a file using following link http://codingfreak.blogspot.in/2010/01/creating-and-using-static-libraries-in.html
i have following Android.mk file in my Android application.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= first-prebuilt
LOCAL_SRC_FILES:= libarith.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := test-main
LOCAL_STATIC_LIBRARIES := first-prebuilt
LOCAL_SRC_FILES := native.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)
When I build application using ndk-build r7b, it gives following error.
Сompile++ thumb : test-main <= native.cpp
SharedLibrary : libtest-main.so
/home/hiren/NDK-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: /home/hiren/workspace/VideoTEST/obj/local/armeabi/libarith.a(addition.o): Relocations in generic ELF (EM: 3)
/home/hiren/workspace/VideoTEST/obj/local/armeabi/libarith.a: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [/home/hiren/workspace/VideoTEST/obj/local/armeabi/libtest-main.so] Error 1
Can anyone help, I am stuck for a long time, here...
Thanks in advance.
You need to build your static librariy in the android format. See also Error in linking C++ static library with android ndk(Error: file format not recognized)