I'm struggling to get a module to compile on Android. It references an already existing shared library -- that I only have the .so and .h files.
My current Android.mk looks like this:
LOCAL_PATH:= $(call my-dir)
EXEC_ARCH := armeabi-v7a
local_vendorlib_c_includes := $(LOCAL_PATH)/VENDORLIB/include
# VENDORLIBWrapper library
include $(CLEAR_VARS)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_SRC_FILES := mylib.cpp
LOCAL_MODULE:= libvendorwrapper
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx
LOCAL_LDLIBS := -L$(LOCAL_PATH)/DPS/$(EXEC_ARCH)/
LOCAL_C_INCLUDES := \
$(call include-path-for, graphics corecg) \
$(call include-path-for, audio-effects) \
$(local_dps_c_includes)
LOCAL_CPPFLAGS += -O2 -Wno-unused-parameter
#--verbose
LOCAL_SHARED_LIBRARIES := \
libcutils \
libdl \
libVendorLib
#LOCAL_PREBUILT_LIBS += libVendorLib
LOCAL_REQUIRED_MODULES := libVendorLib
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE := libVendorLib
LOCAL_SRC_FILES := $(LOCAL_PATH)/VendorLib/$(EXEC_ARCH)/libVendorLib.so
LOCAL_MODULE_TAGS := debug
LOCAL_EXPORT_C_INCLUDES := $(local_vendorlib_c_includes)
include $(PREBUILT_SHARED_LIBRARY)
include $(call all-makefiles-under,$(LOCAL_PATH))
And I am getting the error below:
> ninja: error:
> 'out/target/product/generic/obj/lib/libVendorLib.so.toc', needed by
> 'out/target/product/generic/obj/SHARED_LIBRARIES/libvendorwrapper_intermediates/LINKED/libvendorwrapper.so', missing and no known rule to make it make: *** [ninja_wrapper] Error 1
> make: Leaving directory `/home/donatoaz/WORKING_DIRECTORY'
>
> #### make failed to build some targets (23 seconds) ####
I was able to finally build it by making the following changes
I was able to build it making the following changes:
include $(CLEAR_VARS)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE := libVendorLib
LOCAL_SRC_FILES := libVendorLib.so # <== Moved the prebuilt lib to root / -- oddly enough, when it was in a subfolder, make would not find it.
LOCAL_MODULE_TAGS := debug
LOCAL_EXPORT_C_INCLUDES := $(local_vendorlib_c_includes)
include $(BUILD_PREBUILT) # <== changed this from PREBUILT_SHARED_LIBRARY
Now I get:
make completed successfully (21 seconds)
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 building the AOSP (Oreo)source tree, The following error occurs
build/core/dynamic_binary.mk:17: error: packages/apps/TerminalTest/jni:
LOCAL_MODULE not defined before call to local-intermediates-dir.
18:25:16 ckati failed with: exit status 1
#### failed to build some targets (26 seconds) ####
Application Source tree
jni
Android.mk
src
res
Android.mk
Main Android.mk
LOCAL_PATH:= $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := TerminalTest
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libjni_terminal
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_JNI_SHARED_LIBRARIES := libjni_terminalTest
# TODO: enable proguard once development has settled down
#LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)
jni/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
jni_init.cpp \
com_android_terminal_Terminal.cpp \
LOCAL_C_INCLUDES += \
external/libvterm/include \
libcore/include \
frameworks/base/include
LOCAL_SHARED_LIBRARIES := \
libandroidfw \
libandroid_runtime \
liblog \
libnativehelper \
libutils
LOCAL_STATIC_LIBRARIES := \
libvterm
LOCAL_CFLAGS := \
-Wno-unused-parameter \
LOCAL_MODULE := libjni_terminal
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
Any help will appreciate
If you use LOCAL_MODULE := libjni_terminal in any other project this error will happen.
When using the same LOCAL_MODULE name in different places lead to problems while creating and accessing intermediate files.
Application.mk
APP_STL := gnustl_static
APP_ABI := all
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libz
LOCAL_SRC_FILES := ../prebuild/libz.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include/
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libssl
LOCAL_SRC_FILES := ../prebuild/libssl.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := ../prebuild/libcrypto.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libjson-c
LOCAL_SRC_FILES := ../prebuild/libjson-c.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libcurl
LOCAL_SRC_FILES := ../prebuild/include/libcurlall/$(TARGET_ARCH_ABI)/libcurl.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curl-ndk
LOCAL_SRC_FILES := ../cpp/curl-http.cpp
LOCAL_STATIC_LIBRARIES := libcurl libssl libcrypto libz libjson-c
LOCAL_LDLIBS := -lz -llog -ljnigraphics
include $(BUILD_SHARED_LIBRARY)
clean project and I'm trying to cross compile NDK then show given below error:
/Volumes/Work/Android/Projects/app/src/main/jni/../prebuild/libz.a: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Volumes/Work/Android/Projects/app/src/main/obj/local/arm64-v8a/libcurl-ndk.so] Error 1
Its working on 32 bits fine but 64 bit its show error
Thanks in advance
You're using one prebuilt for all ABIs. You need one prebuilt for each ABI you target. The typical way to write a prebuilt module is like this:
include $(CLEAR_VARS)
LOCAL_MODULE := libz
LOCAL_SRC_FILES := ../prebuild/$(TARGET_ARCH_ABI)/libz.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include/
include $(PREBUILT_STATIC_LIBRARY)
Then you can have prebuild/armeabi-v7a/libz.a, prebuild/arm64-v8a/libz.a, etc. Disable ABIs you don't want to build for (or don't have prebuilts for) using APP_ABI in your Application.mk.
I'm trying to include a fingerprint module. i placed all the .c and .h files in a new directory under /external/ and created an Android.mk file as
########## libdpfpdd ############
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ldpfpdd
LOCAL_SRC_FILES := libdpfpdd.so
include $(PREBUILT_SHARED_LIBRARY)
########### libdpfj ##############
include $(CLEAR_VARS)
LOCAL_MODULE := ldpfj
LOCAL_SRC_FILES := libdpfj.so
include $(PREBUILT_SHARED_LIBRARY)
######### fingerprint ############
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := fingerprint
LOCAL_SRC_FILES := \
enrollment.c helpers.c identification.c \
menu.c sample.c selection.c verification.c
LOCAL_SHARED_LIBRARIES += ldpfpdd ldpfj
include $(BUILD_EXECUTABLE)
after this i tried to do cross compilation as
make TARGET_PRODUCT=am335xevm_sk -j8 OMAPES=4.x
and got the error as
make: *** No rule to make target `out/target/product/am335xevm_sk/obj/lib/ldpfpdd.so', needed by `out/target/product/am335xevm_sk/obj/EXECUTABLES/fingerprint_intermediates/LINKED/fingerprint'. Stop.
make: *** Waiting for unfinished jobs....
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