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)
Related
guys,
My XXX.mk for building the Android executable XXX describes like this:
...
LOCAL_STATIC_LIBRARIES := \
libYYY
LOCAL_MODULE := XXX
LOCAL_PROPRIETARY_MODULE := $(ENABLE_VENDOR_MODULE)
LOCAL_32_BIT_ONLY := true
include $(BUILD_EXECUTABLE)
It is the same directory with the prebuilt libYYY.a and an Android.mk like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/XXX.mk
When executing mm command,
I got the following error:
FAILED: XXX.mk: error: "XXX(EXECUTABLES android-arm) missing libYYY
(STATIC_LIBRARIES android-arm)"
The error is still there even I tried to change LOCAL_STATIC_LIBRARIES to libYYY.a or YYY.
Any suggestion?
I'm using Eclipse for Windows, Android SDK and Android NDK (I'm sure that all paths are set correclty).
I'm looking for compiling a .c library locatad in jni folder, but some error occur. This library depends on external .so libraries, these are my Makefile, Android.mk and library:
jni folder.
Android.mk :
LOCAL_PATH := $(call my-dir)
#---------------------------------------------------------------
include $(CLEAR_VARS)
LOCAL_MODULE := pdbeatdetection
LOCAL_C_INCLUDES := $(LOCAL_PATH)\C:\PROGRAMMING\pd-0.45-4\src
LOCAL_CFLAGS := -DPD
LOCAL_SRC_FILES := pdbeatdetection.c
LOCAL_LDLIBS := -L$(LOCAL_PATH)\C:\PROGRAMMING\PdCore\libs\armeabi\ -lpdnative
include $(BUILD_SHARED_LIBRARY)
Makefile :
all:
C:\PROGRAMMING\android-ndk-r10d\ndk-build.cmd
mkdir ../tmp
cp ..\libs\armeabi\libpdBeatDetection.so ..\tmp\pdbeatdetection.pd_linux
cd ..\tmp && zip externals.zip *.pd_linux && mv externals.zip ..\res\raw
rm -rf ..\tmp
I followed some tutorials, but I'm not still able to solve this issue.
Could you please give me suggestions to compile the library, avoiding the following error?
ERROR:
Description Resource Path Location Type
make.exe: *** [obj/local/armeabi/libpdbeatdetection.so] Error 1 Discoteque C/C++ Problem
Thank you!
If your code depends on an external .so file, you should declare it properly using the PREBUILT_SHARED_LIBRARY macro, like so:
LOCAL_PATH := $(call my-dir)
#dependency
include $(CLEAR_VARS)
LOCAL_MODULE := pdnative
LOCAL_SRC_FILES := C:/PROGRAMMING/PdCore/libs/$(TARGET_ARCH_ABI)/libpdnative.so
LOCAL_EXPORT_C_INCLUDES := C:/PROGRAMMING/pd-0.45-4/src
include $(PREBUILT_SHARED_LIBRARY)
#your module
include $(CLEAR_VARS)
LOCAL_MODULE := pdbeatdetection
LOCAL_SRC_FILES := pdbeatdetection.c
LOCAL_CFLAGS := -DPD
include $(BUILD_SHARED_LIBRARY)
If that's not enough to solve your issue, give us the error reported by calling ndk-build.cmd directly.
I have to use some c++ code in my android application. This code was used successfully in an iOS project.
The code depends on 2 external libraries: zero-mq and protocol buffers.
I compiled the zmq library as an static library like explained here. I added the static (.a) library and the .jar to my project.
I created the protobuf library with the following configurations:
./configure --host=arm-eabi --with-sysroot=x/android-ndk-r10d/platforms/android-21/arch-arm CC="x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot x/android-ndk-r10d/platforms/android-21/arch-arm" --enable-cross-compile --with-protoc=protoc LIBS=-lc
make
I changed the real directories to x to make them shorter.
In my Android Project(IDE: Android Studio) I prepared everything which is necessary. I created a JNI Folder and deactivated the auto-creation of the makefiles.
Application.mk:
APP_MODULE := proxy
APP_STL := gnustl_shared
APP_CPPFLAGS := -frtti -fexceptions --std=c++11
APP_ABI := armeabi-v7a ##all later
NDK_TOOLCHAIN_VERSION := 4.9
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := zmq_static
LOCAL_SRC_FILES := zmq/libzmq.a
include $(PREBUILD_STATIC_LIBRARY)
LOCAL_MODULE := protobuf_static1
LOCAL_SRC_FILES := protobuf/libprotobuf.a
LOCAL_EXPORT_C_INCLUDES := google/protobuf protobuf/
include $(PREBUILD_STATIC_LIBRARY)
LOCAL_MODULE := protobuf_static2
LOCAL_SRC_FILES := protobuf/libprotobuf-lite.a
LOCAL_EXPORT_C_INCLUDES := google/protobuf protobuf/
include $(PREBUILD_STATIC_LIBRARY)
LOCAL_MODULE := protobuf_static3
LOCAL_SRC_FILES := protobuf/libprotoc.a
LOCAL_EXPORT_C_INCLUDES := google/protobuf protobuf/
include $(PREBUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := proxy
LOCAL_CFLAGS := -I/include -pthread -lpthread -D__GXX_EXPERIMENTAL_CXX0X__ - frtti
LOCAL_CPPFLAGS := -I/include -pthread -lpthread -D__GXX_EXPERIMENTAL_CXX0X__ -frtti
LOCAL_CPP_FEATURES += exceptions
LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := \
usersession.cpp\
## LOCAL_ALLOW_UNDEFINED_SYMBOLS := true will compile the code but shutdown on runtime
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\main\jni
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\arm\jni
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\debug\jni
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\armDebug\jni
LOCAL_C_INCLUDES += \zmq
LOCAL_C_INCLUDES += \protobuf
LOCAL_STATIC_LIBRARIES := zmq_static protobuf_static1 protobuf_static2 protobuf_static3
LOCAL_WHOLE_STATIC_LIBRARIES := zmq_static protobuf_static1 protobuf_static2 protobuf_static3
include $(BUILD_SHARED_LIBRARY)
The zmq library is in the subdirectory zmq and the protobuf library is in the subfolder protobuf.
Now the linking of the Objects still does not work. The Error Output when I execute ndk-build:
C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\main\jni>ndk-build
[armeabi-v7a] SharedLibrary : libproxy.so
C:/Users/M/Documents/ndk/sources/cxx-stl/gnu- libstdc++/4.9/include/ext/new_allocator.h:127: error: undefined reference to 'ControlledInstance::ControlledInstan (std::shared_ptr<protogen::Application>, std:
:shared_ptr<protogen::Role>, std::shared_ptr<protogen::User>)'
C:/Users/M/Documents/ndk/sources/cxx-stl/gnu- libstdc++/4.9/include/bits/shared_ptr_base.h:511: error: undefined reference to 'protogen::User::User()'
C:/Users/M/Documents/ndk/sources/cxx-stl/gnu- libstdc++/4.9/include/bits/shared_ptr_base.h:914: error: undefined reference to 'google::protobuf::internal::empty tring_'
C:/Users/M/Dropbox/Workspace/ndk_swig_test/app/src/main//jni/controlledinstance.h :23: error: undefined reference to 'protogen::MetaGraph::~MetaGraph()'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [C:/Users/M/Dropbox/Workspace/ndk_swig_test/app/src/main//obj/local/armeabi- v7a/libproxy.so] Error 1
I tried many versions of the Android.mk and recreated the library more than once with different options which I found all over the internet.
I also looked at dozens of threads on stackoverflow which did not help me.(I'm not allowed to link them because of low reputation)
Additionally i read most of the doc files from the ndk e.g. PREBUILTS.
I added some other directories to my JNI directory e.g. the directory with the original files and directories (compiler, io, stubs...). I think this directory should offer the export of the necessary methods if the prebuild library was successfully linked to my shared library - which is not the case.
I tried far more than I can explain in few minutes and I think it would be overkill if i added everything I've tried because nothing helped.
Because this is my first question I dont have the reputation to include more than 2 links. Sorry for that.
There may probably be other issues as well, but you at least have got a typo - it should be include $(PREBUILT_STATIC_LIBRARY), as in, BUILT, not BUILD.
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
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?