I want to use a pre-built shared library in AOSP. The library is defined in Android.mk like this:
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAG := optional
LOCAL_MODULE_PATH := system/lib
LOCAL_SRC_FILE := system/lib/foo.so
include $(BUILD_PREBUILT)
During build, a folder out/target/product/mako/obj/SHARED_LIBRARIES/foo_intermediates/export_include
was created.
However, the build failed with error message that out/target/product/mako/obj_arm/SHARED_LIBRARIES/foo_intermediates/export_include cannot be found.
Note the difference between "obj" and "obj_arm". What caused the problem?
This is two-target build (arm and arm64), so there are two obj folders, one for 32-bit arm and the other for 64-bit arm.
I need to define the library as follows:
include $(CLEAR_VARS)
LOCAL_MODULE := libfoo
LOCAL_MODULE_SUFFIX :=.so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
ifdef TARGET_2ND_ARCH
LOCAL_MULTILIB := both
LOCAL_MODULE_PATH_64 := system/lib64
LOCAL_SRC_FILES_64 := system/lib64/libfoo.so
LOCAL_MODULE_PATH_32 := system/lib
LOCAL_SRC_FILES_32 := system/lib/libfoo.so
else
LOCAL_MODULE_PATH := system/lib
LOCAL_SRC_FILES := system/lib/libfoo.so
endif
include $(BUILD_PREBUILT)
Related
I am trying to add a prebuilt apk to aosp source but the apk is not geting added.
Android.mk details is like
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)
LOCAL_MODULE := vlc-player
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
include $(BUILD_PREBUILT)
I have also added entry in core.mk under
PRODUCT_PACKAGES +=
vlc-player
but the apk is not added to the build
Remove the flag LOCAL_MODULE_TAGS := optional and try calling the PRODUCT_PACKAGES += vlc-player in your device specific makefile, for example in
device/google/blueline/device.mk
Also manually verify the out directory by running a separate make call like , make vlc if your module is working.
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)
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 need to change Settings app by adding some custom library to it but I am having problems with configuration. When I try to call System.loadLibrary("mylibrary") i get libraryPath=/data/app-lib/com.settings-1: find library returned null. I know that app will look inside /data/app-lib/.. folder for specific library but my library is in system/lib
I know that my .mk files are not OK but I don't know what am I missing, please take look at them.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_JAVA_LIBRARIES := bouncycastle telephony-common
LOCAL_STATIC_JAVA_LIBRARIES := guava android-support-v4 jsr305
ifdef DOLBY_DAP
LOCAL_JAVA_LIBRARIES += framework_ext
else
LOCAL_STATIC_JAVA_LIBRARIES += libsds
endif #DOLBY_DAP
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := Settings
LOCAL_CERTIFICATE := platform
# If this is an unbundled build (to install seprately) then include
# the libraries in the APK, otherwise just put them in /system/lib and
# leave them out of the APK
ifneq (,$(TARGET_BUILD_APPS))
LOCAL_JNI_SHARED_LIBRARIES := efuse_tool
else
LOCAL_REQUIRED_MODULES := efuse_tool
endif
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
include $(BUILD_PACKAGE)
include $(call all-makefiles-under, jni)
ifndef DOLBY_DAP
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libsds:ds.jar
include $(BUILD_MULTI_PREBUILT)
endif
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
And .mk file inside jni folder
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_SRC_FILES := efuse_tool.c
LOCAL_MODULE := efuse_tool
include $(BUILD_SHARED_LIBRARY)
I realized that I have to add prefix "lib" to my library so it will be called from system/lib location. So it should look like this
ifneq (,$(TARGET_BUILD_APPS))
LOCAL_JNI_SHARED_LIBRARIES := libefuse_tool
else
LOCAL_REQUIRED_MODULES := libefuse_tool
endif
LOCAL_MODULE := libefuse_tool
I can also remove LOCAL_JNI_SHARED_LIBRARIES := libefuse_tool because it will never be used.
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