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.
Related
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
I have a Application.mk and a Android.mk file.
Application.mk looks like
NDK_TOOLCHAIN_VERSION := 4.8
APP_PLATFORM := android-9
APP_STL := c++_shared
APP_ABI := armeabi-v7a
and my Android.mk looks like
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo1
LOCAL_SRC_FILES := foo1.cpp
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := foo2
LOCAL_SRC_FILES := foo2.cpp
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
Now I want that library libfoo1 use c++_shared for APP_STL and libfoo2 use c++_static for APP_STL. (I know, normally that should not be made relation between app_stl values with static and shared build android). Is there a easy way without building a extra project and import the library to the other project?
Yes, it is possible. Do the following changes:
# Application.mk
APP_STL := none
This way you disable internal logic of choosing STL implementation of NDK build system. Now, specify manually which C++ stdlib implementation you want link with:
# Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo1
LOCAL_SRC_FILES := foo1.cpp
LOCAL_SHARED_LIBRARIES := c++_shared
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := foo2
LOCAL_SRC_FILES := foo2.cpp
LOCAL_STATIC_LIBRARIES := c++_static
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cxx-stl/llvm-libc++)
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
I am trying to use a boost library inside my android application, using the NDK. I have found a couple of success stories here and here, but I can't say the same about me. I am specifically trying to use the library in this link, as well as the boost thread library. In the code below, I am only trying to include the thread library, not the math library. The process I used to build the boost libraries is pretty much the same as the first link I attached.
So far, it seems I have successfully built the boost libraries, but when I run ndk-build, I get the following error:
Prebuilt : libboost_thread.a <= <NDK>/sources/
cp: omitting directory `path/to/ndk/sources/boost'
make: *** [obj/local/armeabi/libboost_thread.a] Error 1
Obviously the cp: omitting directory... is not exactly an error. But the only thing I'm getting other than that is the next line, which doesn't really mean anything. Error 1
Here's my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := boost_thread
LOCAL_LDLIBS := lboost_system-gcc-md lboost_thread-gcc-md -lgnustl_static
LOCAL_LDLIBS += lboost_system-gcc-md lboost_thread-gcc-md \
-L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi \
-lgnustl_static
LOCAL_SRC_FILES := #cpp_sources
LOCAL_MODULE := com_example_ndkFile_CppMethods
include $(BUILD_SHARED_LIBRARY)
$(call import-module,boost)
And there's also an Android.mk file in path/to/ndk/sources/boost/:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_thread
LOCAL_SRC_FILES:= android/lib/libboost_thread.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
And my humble Application.mk file:
APP_ABI := armeabi armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS = -fexceptions
I built the boost libraries using bjam. All of the libboost_###.a files are in the sources/boost/android/lib folder.
What is the error I'm getting?
I built the boost libraries using Boost-for-Android. Then I have in my boost/include/lib directory the android makefile boost.mk
LOCAL_PATH := $(call my-dir)
# boost_date_time
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_date_time
LOCAL_SRC_FILES := libboost_date_time-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_filesystem
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_filesystem
LOCAL_SRC_FILES := libboost_filesystem-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_thread
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_thread
LOCAL_SRC_FILES := libboost_thread-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_system
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_system
LOCAL_SRC_FILES := libboost_system-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_program_options
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_program_options
LOCAL_SRC_FILES := libboost_program_options-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_chrono
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_chrono
LOCAL_SRC_FILES := libboost_chrono-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
and my module where i use some of the boost libraries looks like this
LOCAL_PATH := $(call my-dir)
# SignalServer, executable
#
include $(CLEAR_VARS)
LOCAL_CFLAGS := -DTIXML_USE_TICPP
#LOCAL_CFLAGS += -DDEBUG
LOCAL_STATIC_LIBRARIES := boost_thread \
boost_system \
boost_filesystem \
boost_program_options \
boost_chrono \
LOCAL_STATIC_LIBRARIES += ticpp \
tia \
tobicore \
tobiid \
tid \
gdf
LOCAL_MODULE := signalserver
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/extern/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../boost/include/boost-1_53
LOCAL_SRC_FILES := #cpp source
include $(BUILD_EXECUTABLE)
in addition I have an Android.mk where all subdir makefiles are listed
TOP_PATH := $(call my-dir)
include $(TOP_PATH)/boost/lib/boost.mk
include $(TOP_PATH)/signalserver/signalserver.mk
.
.
and my Application.mk:
APP_PLATFORM := android-14
APP_ABI := armeabi-v7a
#APP_OPTIM := debug
#NDK_DEBUG := 1
NDK_TOOLCHAIN_VERSION := 4.6
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
Here: http://silverglint.com/boost-for-android/ you can find a simple script that lets you build a modern version of boost for android, or simply download prebuilt boost binaries.
Also included is a sample test app that shows you how to include/link the boost headers/binaries
I use this AES library (in C language),
http://gladman.plushost.co.uk/oldsite/AES/aes-src-16-04-07.zip
I follow this page and use the commds mentioned to compile libaes.a,
http://forums.devshed.com/c-programming-42/aes-encrypt-decrypt-in-c-687368.html
gcc -c -O2 -fomit-frame-pointer aescrypt.c aeskey.c aestab.c aes_modes.c
ar rcs libaes.a *.o
I can compile and run my program using the libaes.a without problem.
However if use ndk-build to compile my program (indeed modified a little),
I always get this error message and fail to compile...
"...member aes_modes.o in archive is not an object..."
what's wrong with that file?
Or what's wrong with the process?
my Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libaes
LOCAL_SRC_FILES := libaes.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_C_INCLUDES :=\
/android-ndk-r6b/platforms/android-8/arch-arm/usr/include\
/android-ndk-r6b/samples/hello-jni/jni/libaes
LOCAL_WHOLE_STATIC_LIBRARIES := libaes
include $(BUILD_SHARED_LIBRARY)
I've a feeling that you compiled aes with native tools (x86) and using it as prebuild library. I've tried this Android.mk and it works:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := aes
LOCAL_SRC_FILES := aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := jni/aes
LOCAL_STATIC_LIBRARIES := aes
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
Just unzip aes-src-16-04-07.zip into jni/aes. I think it is better to use ndk build system because it can set all necesary options.
And hello-jni.c (just in case):
#include <aes.h>
void test() {
aes_init();
}