Is there any way that we can build different kind of static libraries (.a extension files) at once, that we created through our NDK ? I think you'll understand better when i shared the code.
Android.mk ->
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libzlib
LOCAL_SRC_FILES := libzlib.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpng
LOCAL_SRC_FILES := libpng.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := callNDK
LOCAL_SRC_FILES := callNDK.c
LOCAL_STATIC_LIBRARIES := libpng libzlib
include $(BUILD_SHARED_LIBRARY)
The static libraries that I include, I copied from the /obj folder that I created with the BUILD_STATIC_LIBRARY. How can I prebuilt them all at once and include them ? Sorry for the bad English and thanks in advance !
I was able to find the answer with the variable, TARGET_ARCH_ABI. Adding LOCAL_SRC_FILES := ..\obj\local\$(TARGET_ARCH_ABI)\libzlib.a line on each prebuilt library fixed the problem. Basiclly, it chooses the appropriate library on each compile & install.
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 got a problem in android.mk.It always show me that cannot find -lsubstrate-dvm and -lsubstrate. I don't know what it is? Could someone tell me how to solve this problem ? Here is the logcat:
Android NDK:non-system libraries in linker flags: -libsubstrate-dvm -libsubstrate
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
cannot find -libsubstrate-dvm
cannot find -libsubstrate
Here is the android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := substrate
LOCAL_SRC_FILES := libsubstrate.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := substrate-dvm
LOCAL_SRC_FILES := libsubstrate-dvm.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := cydiasubstrate.cy
LOCAL_SRC_FILES := cydiasubstrate.cy.cpp
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH) -lsubstrate-dvm -lsubstrate -lz
LOCAL_ARM_MODE := arm
APP_ALLOW_MISSING_DEPS=true
include $(BUILD_SHARED_LIBRARY)
please help me to fix this issue.
substrate-dvm is the name of the module being built, it relies on a prebuild library, not on sources, so you should look for libsubstrate-dvm.so
You could follow the following link for further help:
https://blog.gdssecurity.com/labs/2014/12/16/hooking-non-public-methods-with-the-ndk-using-mobile-substra.html
to include the Substrate libraries. The easiest way to
do this is to navigate to the ‘/sdk/extras/saurikit/cydia_substrate/’
directory and copy ‘substrate.h’ and navigate to the
‘/sdk/extras/saurikit/cydia_substrate/lib//’ directory and copy
‘libsubstrate-dvm.so’ file into the jni folder of the project.
I created a static C++ library for testing. It only defines a class, MyLibrary, and the constructor MyLibrary::MyLibrary(). I built it in qtcreator, and got a libMyLibrary.a file, which is a prebuilt static library.
I would like to use this library in an Android project (using the NDK). In a working NDK test project, I therefore added a folder called inc at the same level as jni, in which I put libMyLibrary.a and its corresponding header mylibrary.h.
My Android.mk is as follows:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyLibrary
LOCAL_SRC_FILES := ../inc/libMyLibrary.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := helloJNI
LOCAL_SRC_FILES := mainActivity.cpp
LOCAL_C_INCLUDES += inc
LOCAL_STATIC_LIBRARIES := MyLibrary
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
The ndk-build command compiles without any error. But my static library is apparently not linked (i.e. it does not appear in obj/local/armeabi/objs).
I have tried to include it in my mainActivity.cpp file, but even though the header (mylibrary.h) is found, the library is not and I cannot create an object as in:
MyLibrary test = MyLibrary();
What am I doing wrong? I have read tens of similar questions on StackOverflow, but I still don't get it.
try to use this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := helloJNI
LOCAL_SRC_FILES := mainActivity.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc/
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/inc/ -lMyLibrary
include $(BUILD_SHARED_LIBRARY)
move libMyLibrary.a & mylibrary.h to jni/inc/libMyLibrary.a
hi, i need to use a prebuilt library in my native code so i am placing the library following the example in ndk/samples/native-activity. Below is the structure. Please some one help me out with this error, dsplink.h can not be found. Thanks in advance :)
I thin Vladimir was on the right track.
But don't keep the static lib in the obj folder since that one is delete every run, instead create a jni/modules/precompiled or something and put the stuff there...
what you have is a precompiled static lib. that's what the .a file is.
it's meant to add it to a compilation process so that it'll be in the final binary.
so what you should have is :
#
# DSPLINK
#
include $(CLEAR_VARS)
LOCAL_MODULE := dsplink
LOCAL_SRC_FILES := [path-to-prebuilt-lib]/libdsplink.a
LOCAL_EXPORT_C_INCLUDES := [path-to-dsplink-headers-folder]
include $(PREBUILT_STATIC_LIBRARY)
and also dont forget to include it for the linker in the project .. so below this section in the main shared lib add this line :
LOCAL_STATIC_LIBRARIES := dsplink
Your C file includes dsplink.h file. If you have it, you should add the full path to this file in LOCAL_C_INCLUDES, e.g.
LOCAL_MODULE := jnihello
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inlcudes
By the way, if dsplink.a file is prebuilt, you will be on the safe side to keep it outside of the libs/ folder, so that make clean does not delete it. You can use something like
LOCAL_LDFLAGS += $(LOCAL_PATH)/prebuilt/dsplink.a
to help the linker find the file.
libmath-prebuilt.so is a prebuilt library which has some functions which are used by buyya_read.c. First generate libmath-prebuilt.so using ndk-build and keep in jni folder where buyya_read.c is kept in ur project in elcipse.
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := math-prebuilt
LOCAL_SRC_FILES = libmath-prebuilt.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := buyya_read
LOCAL_SRC_FILES := buyya_read.c
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := math-prebuilt
include $(BUILD_SHARED_LIBRARY)
You see the project directory structure in below image.
You should define prebuilt library dsplink in your Android.mk before jnihello project:
#
# DSPLINK
#
include $(CLEAR_VARS)
LOCAL_MODULE := dsplink
LOCAL_SRC_FILES := [path]/libs/armeabi/libdsplink.so
LOCAL_EXPORT_C_INCLUDES := [directory-with-dsplink.h-file]
include $(PREBUILT_STATIC_LIBRARY)
...
# jnihello
i'm wrapping a native API to Android by NDK.
But when building it don't find the header files.
I have the following structure.
project/jni
Android.mk
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
LOCAL_PATH :=/home/marcos/dev/workspace/rmsdk.native.wraper/jni
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1
LOCAL_SRC_FILES := native.c DelegateDRMProcessorClient.cpp
LOCAL_STATIC_LIBRARY := adept cryptopenssl dp expat fonts hobbes jpeg mschema png t3 xml zlib
include $(BUILD_SHARED_LIBRARY)
project/jni/prereqs/
Android.mk (Used to call all subdirs Android.mk files)
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
project/jni/prereqs/%lib%/
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE :=dp
LOCAL_SRC_FILES :=libdp.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
And there's a include folder on each %lib% folder.
When using ndk-build I get a
"/home/marcos/dev/workspace/rmsdk.native.wraper/jni/DelegateDRMProcessorClient.h:18:20: error: dp_all.h: No such file or directory"
Anyone knows how to include these header to be available to the compiler?
I solve it, getting all the headers in a folder and including the following line in the Android.mk
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include-all
This works, but not looks like the best approach.
I'm a bit late to this party, but ran into the same issue and might have an answer for your comment:
"This works, but not looks like the best approach"
There;s a sample in the NDK called "module-exports"
It shows how to construct an Android.mk file which respects header files living in their proper directories and not all dumped into a single include directory.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo/foo.c
LOCAL_CFLAGS := -DFOO=2
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
LOCAL_EXPORT_CFLAGS := -DFOO=1
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bar
LOCAL_SRC_FILES := bar/bar.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar
LOCAL_STATIC_LIBRARIES := foo
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := zoo
LOCAL_SRC_FILES := zoo/zoo.c
LOCAL_SHARED_LIBRARIES := bar
include $(BUILD_SHARED_LIBRARY)
Years later...
To export the include directory instead of individual files, I use the following:
LOCAL_EXPORT_C_INCLUDE_DIRS := $(MY_DIRECTORY_PATH)
For example, for the above question the export for "foo" would look like:
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/foo
For new people's convenience, I just want to add that move all your header files in folder which is referred by LOCAL_C_INCLUDES := $(LOCAL_PATH) and then save android.mk and restart eclipse. After trying all the above solutions, that worked for me.