I have a shared lib (ex. libcrypto.so), but don't have header files.
Can I use this lib in other module?
I tried to use LOCAL_EXPORT_C_INCLUDES to export header files, but It doesn't work.
This is prebuilt module:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libcrypto.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
And, this is module used libcrypto:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES += test.c # include "openssl/crypto.h"
LOCAL_C_INCLUDES += $(crypto_PATH)/include
LOCAL_SHARED_LIBRARIES += libcrypto
LOCAL_MODULE := libtest
LOCAL_MODULE_TAGS := optional
LOCAL_ARM_MODE := arm
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
This is libcrypto module (boringssl):
LOCAL_PATH := $(call my-dir)
# Target shared library
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libcrypto
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/src/include
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/crypto-sources.mk
LOCAL_SDK_VERSION := 9
LOCAL_CFLAGS += -fvisibility=hidden -DBORINGSSL_SHARED_LIBRARY -DBORINGSSL_IMPLEMENTATION -DOPENSSL_SMALL -Wno-unused-parameter
# sha256-armv4.S does not compile with clang.
LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
LOCAL_CLANG_ASFLAGS_arm64 += -march=armv8-a+crypto
include $(LOCAL_PATH)/crypto-sources.mk
include $(BUILD_SHARED_LIBRARY)
EDIT: Added boringssl module. I actually used #include "openssl/crypto.h" in test.c
Usually, you find crypto.h under include/openssl. So, in your case, either change the #include statement in test.c
#include "openssl/crypto.h"
Or (less recommended), edit
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/openssl
Related
I have 2 Android.mk files with the first one building a bunch of libraries and the second one builds another library, but needs the first one to be complete before kicking off it's own build. Is there any way to make sure this happens?
This is what I've tried so far:
LOCAL_ADDITIONAL_DEPENDENCIES := path/to/folder/for/android1.mk
Order of listing of these Android.m files (1 & 2)
Adding LOCAL_SHARED_LIBRARIES := a.so b.so ...
But, none of these have helped so far
######################################################################
# Android1.mk
######################################################################
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := a1.c a2.c
LOCAL_MODULE := lib_a
LOCAL_MODULE_TAGS := optional
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := b1.c b2.c
LOCAL_MODULE := lib_b
LOCAL_MODULE_TAGS := optional
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_SHARED_LIBRARY)
######################################################################
# Android2.mk
######################################################################
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := abc.c xyz.c
LOCAL_MODULE := lib_2
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_TAGS := optional
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_ADDITIONAL_DEPENDENCIES := /path/to/folder/where/Android1.mk/resides
LOCAL_SHARED_LIBRARIES += \
lib_a \
lib_b
include $(BUILD_SHARED_LIBRARY)
The caveat is that abc.c/xyz.c doesn't make any calls in lib_a.so/lib_b.so/lib_z.so. But, I'm generating a script (in Android2.mk) and for that, require all the libraries (in Android1.mk) to be built prior
Found a way to achieve this:
# List out all the dependencies here
INTERMEDIATE_TARGET := \
lib_1
lib_2
generate.abc: $(INTERMEDIATE_TARGET)
While transforming my project from eclipse to AS.
I got a fatal error which caused by "the lib not found " problem.
My project contains jni codes,compiled by ndk build system and managed by the "Android.mk" file.
After transformed I found that two of the libraries(.so) was not packaged into the apk file while other libraries are packaged correctly.
Here is part of the content of "Android.mk" file,all libraries are packaged but "curl" and "jsqlite".The two files do exist in the right path.Is there any suggestion,thks!!
LOCAL_PATH := $(call my-dir)
MY_LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := skia
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libskia.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := iconv
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libiconv.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS :=
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := jsqlite
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libjsqlite.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curl
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libcurl.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS :=
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libgdal.so
LOCAL_SHARED_LIBRARIES := jsqlite
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_SHARED_LIBRARY)
I have an Android application project that depends on two native libraries, libA and libB. libA depends on libB, and both libraries are built using APP_STL:=gnustl_shared. The problem then arises when trying to build the APK:
[2014-09-30 14:31:47 - Appname] Error generating final archive: Found duplicate file for APK: lib/armeabi/libgnustl_shared.so
Origin 1: /libA/libs/armeabi/libgnustl_shared.so
Origin 2: /libB/libs/armeabi/libgnustl_shared.so
How do I configure these libraries to build/link properly while using a common shared library such as libgnustl_shared.so?
EDIT:
I have tried many alternative makefile settings, so it's hard to know what to post here, but I'll try. Both Application.mk files in libA/jni and libB/jni contain:
APP_STL := gnustl_shared
APP_OPTIM := release
APP_ABI := armeabi-v7a armeabi
APP_PLATFORM := android-15
In libA/jni, the Android.mk file contains:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyBase
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libMyBase.so
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := Base
LOCAL_SRC_FILES := Base.cpp
LOCAL_C_INCLUDES := ../../../../LIBS/MyBase/pub/include
LOCAL_LDLIBS := -llog -ljnigraphics
LOCAL_SHARED_LIBRARIES := MyBase
LOCAL_CPP_FEATURES += rtti
LOCAL_CPP_FEATURES += exceptions
include $(BUILD_SHARED_LIBRARY)
In libB/jni, the Android.mk file contains:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyMedia
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libMyMedia.so
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := Media
LOCAL_SRC_FILES := Media.cpp media_jni.cpp
LOCAL_C_INCLUDES := ../../../../LIBS/MyBase/pub/include \
../../../../LIBS/MyMedia/pub/include
LOCAL_LDLIBS := -llog -ljnigraphics
LOCAL_SHARED_LIBRARIES := MyBase MyMedia
LOCAL_CPP_FEATURES += rtti
LOCAL_CPP_FEATURES += exceptions
include $(BUILD_SHARED_LIBRARY)
$(call import-module,LIBS/MyBase/jni)
MyBase and MyMedia are two native libraries written in C++ and are not Java/JNI aware. MyMedia is dependent on MyBase. Both libraries are dependent on a robust C++ library such as gnustl_shared.
I am trying to use pjsip on android.. after ./configure-android and make dep and make commands, static libraries were generated 13 of them.
I used the include folder which is copied inside jni folder. The content of android.mk in jni folder is as follows:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libpj-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpj-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjlib-util-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjlib-util-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../voiper/pjsip_lib/libpjmedia-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-audiodev-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-audiodev-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-codec-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-codec-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-videodev-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-videodev-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjnath-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjnath-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsdp-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsdp-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsip-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsip-simple-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-simple-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsip-ua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-ua-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsua2-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsua2-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsua-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := dummy_pjsip_jni_module
LOCAL_SRC_FILES := dummy_pjsua.c
LOCAL_EXPORT_C_INCLUDES += ./include
LOCAL_C_INCLUDES += ./include
LOCAL_STATIC_LIBRARIES := libpj-arm-unknown-linux-androideabi libpjlib-util-arm-unknown-linux-androideabi libpjmedia-arm-unknown-linux-androideabi libpjmedia-audiodev-arm-unknown-linux-androideabi libpjmedia-codec-arm-unknown-linux-androideabi libpjmedia-videodev-arm-unknown-linux-androideabi libpjnath-arm-unknown-linux-androideabi libpjsdp-arm-unknown-linux-androideabi libpjsip-arm-unknown-linux-androideabi libpjsip-simple-arm-unknown-linux-androideabi libpjsip-ua-arm-unknown-linux-androideabi libpjsua2-arm-unknown-linux-androideabi libpjsua-arm-unknown-linux-androideabi
include $(BUILD_SHARED_LIBRARY)
I wrote a simple one line c file that only includes a header file inside include folder. Then i run ndk-build from the project directory and get no such file for the header file which is present inside the include folder. There is no application.mk.. What am i missing?
EDIT
the '.' represents the current directory.. "include" folder is inside jni folder
There are several issues here:
1) Each prebuilt static library should have its own module definition, i.e. your Android.mk should look like:
include $(CLEAR_VARS)
LOCAL_MODULE := libpj
LOCAL_SRC_FILES := libpj-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpjlib-util
LOCAL_SRC_FILES := libpjlib-util-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)
... etc
Note that the module name doesn't have to be exactly the same as the file path, which makes things a little clearer for the rest.
2) That '.' will refer, at build time, to the current directory where you invoke ndk-build, you need to use $(LOCAL_PATH)/include instead to refer to the right include path (assuming your Android.mk is under jni/ too). I.e.:
include $(CLEAR_VARS)
LOCAL_MODULE := dummy_pjsip_jni_module
LOCAL_SRC_FILES := dummy_pjsua.c
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := libpj libpjlib-util libpjmedia libpjmedia-audiodev \
libpjmedia-codec libpjmedia-videodev libpjnath \
libpjsdp libpjsip libpjsip-simple libpjsip-ua \
libpjsua2 libpjsua
include $(BUILD_SHARED_LIBRARY)
I want to use tow extern library to build android application of tracking object with surf algorithm so I used this tutorial Using OpenCV Nonfree Module (SIFT, SURF) in Android NDK Projects
the first library is libobjtrack_opencv_jni.so (using for tracking) an the 2 others are libopencv_java.so and libobjtrack_opencv_jni.so
I finished To Get this result:
Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sift_prebuilt
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_java_prebuilt
LOCAL_SRC_FILES := libopencv_java.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := objtrack_opencv_jni
LOCAL_SRC_FILES := libobjtrack_opencv_jni.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE := STATIC
OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
include C:/OpenCV-2.4.5-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_C_INCLUDES:= C:/OpenCV-2.4.5-android-sdk/sdk/native/jni/include
LOCAL_MODULE := test_sift12
LOCAL_CFLAGS := -Werror -O3 -ffast-math
LOCAL_LDLIBS += -llog -ldl
LOCAL_SHARED_LIBRARIES := sift_prebuilt opencv_java_prebuilt objtrack_opencv_jni
LOCAL_SRC_FILES := test_sift.cpp
include $(BUILD_SHARED_LIBRARY)
build is succeeded and i got test_sift12.so but is not work when i run the .apk .. I think that the problem is with the use of PREBUILT_SHARED_LIBRARY in android.mk file .
i need your help
load library, where you want to use that libraries in the activity.
like in this way
public class YourClassName extends Activity {
.....
//add the following code at the end of the class
static
{
System.loadlibrary("opencv_java");
System.loadlibrary("objtrack_opencv_jni");
System.loadlibrary("nonfree");
System.loadlibrary("test_sift12");
}
}
I suggest you change you names of following
LOCAL_MODULE := sift_prebuilt
to
LOCAL_MODULE := nonfree
and
LOCAL_MODULE := opencv_java_prebuilt
to
LOCAL_MODULE := opencv_java
Remember don't forget to modify the names in LOCAL_SHARED_LIBRARIES