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.
Related
I am using prebuilt openssl in my project.after loading app is crashing and giving this error
java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libcrypto.so.1.0.0" needed by "libPrivateSsl.so"; caused by library "libcrypto.so.1.0.0" not found
my android.mk looks like this
LOCAL_PATH := $(call my-dir)
# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libPrivateSsl.so
include $(PREBUILT_SHARED_LIBRARY)
# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libPrivateCrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := myLibrary
TARGET_PLATFORM := android-3
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := ssl crypto
include $(BUILD_SHARED_LIBRARY)
loading library in activity like this
static {
System.loadLibrary("PrivateSsl");
System.loadLibrary("PrivateCrypto");
System.loadLibrary("myLibrary");
}
i am using Kit-kat for testing with Ubuntu System.
please help me to solve this error.
You downloaded some wrong version of OpenSSL for Android, which was not built correctly (similar to this one. Android does not support versioning in SONAMEs.
You can find a better prebuilt version of OpenSSL, but this is not recommended. For these libraries to be entrusted with your secret communications, you should better make sure that you yourself build it from a trusted (official) source, and it does not leak your private information to some rogue third party.
As a minimal fix, you can try to use the patchelf utility to fix the SONAME in your library.
i solved this issue by making some little changes in android.mk file
i removed .so files and placed .a files.
my android.mk looks like this now
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ssl_static
LOCAL_SRC_FILES := precompiled/libssl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := crypto_static
LOCAL_SRC_FILES :=precompiled/libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := myLibrary
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := ssl_static crypto_static
include $(BUILD_SHARED_LIBRARY)
got this idea from here
link
I tried to compile a shared library and an executable which use these library.
All sources and headers are in the same directory.
I use these Android.mk
==================libsample.so
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libsample
LOCAL_MODULE_TAGS = optional
LOCAL_PRELINK_MODULE := false
LOCAL_SRC_FILES := libsample.c
include $(BUILD_SHARED_LIBRARY)
=======================tstsample
include $(CLEAR_VARS)
LOCAL_MODULE := tstsample
LOCAL_SHARED_LIBRARY := libsample
LOCAL_CFLAGS :=-w
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := cmd.c main.c test.c
include $(BUILD_EXECUTABLE)
===================================
I obtained these error :
error: undefined reference to "each function of my library"
My library is compiled and put in the directory :
:
out/target/product/boadname/system/lib/
I also copied this library in the current directory. but I obtained the same error.
Do you have any suggestions?
Thanks by advance
If this was not a typo while copying your Android.mk to SO, then the following sed command should resolve your problem:
s/LOCAL_SHARED_LIBRARY/LOCAL_SHARED_LIBRARIES/
I want to build an shared library. To build it, I need to call another shared library. Here is what I did:
1.Create one Android project,named "BuildLib",and add a new folder "jni" under the project directory. Contents of jni folder:
jni-->Android.mk
-->Application.mk
-->add.cpp
-->add.h add.cpp just do two numbers addition:
add.h:
int add(int a,int b);
add.cpp:
#include "add.h"
int add(int a,int b){
return a+b;}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := add.cpp
LOCAL_MODULE := add
include $(BUILD_SHARED_LIBRARY)
After build the project,I got libadd.so under directory $(BUILDLIB)/libs/armeabi/.
Create another Android project, named "CallLib". Copy libadd.so and add.h to jni folder, create Android.mk, Application.mk, and call_add.cpp.
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := libadd.so
LOCAL_MODULE := add_prebuilt
include $(PREBUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := call_add.cpp
LOCAL_MODULE := native
LOCAL_SHARED_LIBRARIES := add_prebuilt
include $(BUILD_SHARED_LIBRARY)
call_add.cpp:
#include "add.h"
int call_add(){return add(1,2);}
After all above, I build the CallLib project, but got the error:
undefined reference to 'add(int, int)';
I think the libadd.so can not be found, but I don't know how to modify. Does anyone know how I can fix this? Any help will be appreciated.
In your second Android.mk, try replacing the first module with:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := libadd.so
LOCAL_MODULE := add_prebuilt
LOCAL_EXPORT_C_INCLUDES := add.h
include $(PREBUILD_SHARED_LIBRARY)
The LOCAL_EXPORT_C_INCLUDES flag should attach the header information to the add_prebuilt module, so it can be linked with your final library.
Just in case anyone needs it:
A bit hackish way to keep the linker happy:
LOCAL_LDLIBS := -llog
or
LOCAL_LDLIBS := -L$(LOCAL_PATH)/lib -lMyStuff
Less hackish:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := xyz
LOCAL_SRC_FILES += xyz/xyz.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY) # this builds libxyz.so
include $(CLEAR_VARS)
LOCAL_MODULE := abc
LOCAL_SHARED_LIBRARIES := xyz # <=== !!! this makes libabc.so dependent on libxyz.so
LOCAL_SRC_FILES := abc/abc.c
#LOCAL_LDLIBS := ...
include $(BUILD_SHARED_LIBRARY) # this builds libabc.so
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 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.