I have a prebuilt shared library with name "libaudio_ns.so" and I want the libaudiofinger.so link to this lib.
I do as below:
Adding prebuilt lib to android/external/ns/lib/libaudio_ns.so with Android.mk as below:
`include $(CLEAR_VARS)
LOCAL_MODULE := libaudio_ns
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_MULTILIB := both
LOCAL_SRC_FILES_arm := lib/libaudio_ns.so
LOCAL_SRC_FILES_arm64 := lib64/libaudio_ns.so
LOCAL_MODULE_TARGET_ARCH := arm arm64
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_MODULE_TAGS := optional
include $(PREBUILT_SHARED_LIBRARY)`
in file framework/av/services/audioflinger/Android.bq, I added "libaudio_ns"
shared_libs: [
"libaudiofoundation",
"libaudiohal",
+"libaudio_ns",
"libaudioprocessing",
"libaudiospdif",
"libaudioutils",
"libcutils",
"libutils",
"liblog",
],
but have an error during compile as below:
[ 99% 719/720] glob vr.prof
[100% 720/720] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
FAILED: out/soong/build.ninja
out/soong/.bootstrap/bin/soong_build -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/build.ninja.d -globFile out/soong/.bootstrap/build-globs.ninja -o
out/soong/build.ninja Android.bp
error: frameworks/av/services/audioflinger/Android.bp:3:1: "libaudioflinger" depends on undefined module "libaudio_ns"
ninja: build stopped: subcommand failed.
15:24:33 soong bootstrap failed with: exit status 1
failed to build some targets (10:29 (mm:ss))
Note: libaudiflinger.so is located in system/lib64
Could you help to fix this issue or give me any suggestion for this problem?
Thank you so much!
I think you need to add libaudio_ns dependency to LOCAL_SHARED_LIBRARIES of audioflinger module.
Since you're adding a prebuilt .so file, you probably could use PRODUCT_COPY_FILES approach, see importing custom SO file to AOSP
EDITED: Sorry, that won't work. Seems that you need to convert .mk file to .bp, and only then Soong will see it.
See https://groups.google.com/g/android-building/c/IjNEMlA5lj4
FYI there's a tool to convert .mk to .bp, called androidmk https://stackoverflow.com/a/48593871/1028256
Related
I'm trying to get this sample project to build with ndk-build, but for some reason it doesn't find the libraries. This is the error message I get:
build-binary.mk:688: Android NDK: Module fastcvFeatDetect depends on undefined modules:
log GLESv2
I don't know enough about ndk to know how to check if these libraries are available and if I'm pointing to their path correctly.
There's this master make file at the top level:
# An Android.mk file must begin with the definition of the LOCAL_PATH variable.
# It is used to locate source files in the development tree. In this example,
# the macro function 'my-dir', provided by the build system, is used to return
# the path of the current directory (i.e. the directory containing the
# Android.mk file itself).
#
LOCAL_PATH := $(call my-dir)
JNI_DIR := $(LOCAL_PATH)
UTILS_DIR := $(LOCAL_PATH)/utils
# The function "$(call all-subdir-makefiles)" returns a list of Android.mk
# files located in all sub-directories of the current 'my-dir' path.
# This function can be used to provide deep-nested source directory
# hierarchies to the build system.
#
include $(call all-subdir-makefiles)
Followed by these make files in the sub-directories:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE:= false
# This variable determines the OpenGL ES API version to use:
# If set to true, OpenGL ES 1.1 is used, otherwise OpenGL ES 2.0.
USE_OPENGL_ES_1_1 := false
# Set OpenGL ES version-specific settings.
ifeq ($(USE_OPENGL_ES_1_1), true)
OPENGLES_LIB := -lGLESv1_CM
OPENGLES_DEF := -DUSE_OPENGL_ES_1_1
else
OPENGLES_LIB := -lGLESv2
OPENGLES_DEF := -DUSE_OPENGL_ES_2_0
endif
# An optional set of compiler flags that will be passed when building
# C ***AND*** C++ source files.
#
# NOTE: flag "-Wno-write-strings" removes warning about deprecated conversion
# from string constant to 'char*'
LOCAL_CFLAGS := -Wno-write-strings $(OPENGLES_DEF)
# The list of additional linker flags to be used when building your
# module. This is useful to pass the name of specific system libraries
# with the "-l" prefix.
LOCAL_LDLIBS := \
-llog $(OPENGLES_LIB)
LOCAL_LDFLAGS:= -Wl,--no-fix-cortex-a8
LOCAL_MODULE := libfastcvFeatDetect
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := ../About.cpp Corner.cpp
LOCAL_STATIC_LIBRARIES := libfastcv libfastcvUtils
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_C_INCLUDES += $(JNI_DIR)/fastcv
LOCAL_C_INCLUDES += $(JNI_DIR)
LOCAL_MODULE_OWNER := qcom
LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_SHARED_LIBRARY)
I've tried changing some things based on googling around, but so far nothing has worked. Does anyone have any advice?
LOCAL_PRELINK_MODULE:= false
This isn't an NDK sample. This is platform code. It is built with the AOSP build system, not the NDK. See https://source.android.com/setup/build/building for more information on that.
If you're trying to find NDK samples, see https://github.com/googlesamples/android-ndk.
If you really do need to build this non-NDK project with the NDK, read on.
Grepping for the error message in $NDK/build is often a good way to find more information:
$(call __ndk_warning,Module $(LOCAL_MODULE) depends on undefined modules: $(undefined_libs))
# https://github.com/android-ndk/ndk/issues/208
# ndk-build didn't used to fail the build for a missing dependency. This
# seems to have always been the behavior, so there's a good chance that
# there are builds out there that depend on this behavior (as of right now,
# anything using libc++ on ARM has this problem because of libunwind).
#
# By default we will abort in this situation because this is so completely
# broken. A user may define APP_ALLOW_MISSING_DEPS to "true" in their
# Application.mk or on the command line to revert to the old, broken
# behavior.
ifneq ($(APP_ALLOW_MISSING_DEPS),true)
$(call __ndk_error,Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies))
endif
This used to be silently ignored and it is now an error. It's pointing out the following bugs:
LOCAL_SHARED_LIBRARIES := liblog
This line does nothing. Delete it. System libraries are linked with LOCAL_LDLIBS, not LOCAL_SHARED_LIRBARIES. There will be a similar line somewhere else causing the error for GLESv2.
I am getting a compile error:
undefined reference to 'TangoService_getConfig' (MoreTeapotsNativeActivity.cpp)
ld returned 1 exit status (collect2.exe)
I am working with the tango sdk TangoSDK_Ikariotikos_C.zip in Visual Studio 2015 using VisualGDB. I have also replicated the error in Android Studio so it isn't IDE specific.
I have started with an NDK sample project to test a native activity deploys correctly and reduce complexity whilst troubleshooting. I have used VisualGDB MoreTeaPotsNativeActivity but any will do. The app compiles and runs on our ASUS Zenfone AR. Once I include tango_client_api.h and add the following code, I get the compile error:
TangoCoordinateFramePair* Tango_FramePair;
Tango_FramePair = new TangoCoordinateFramePair();
Tango_FramePair->base = TANGO_COORDINATE_FRAME_START_OF_SERVICE;
Tango_FramePair->target = TANGO_COORDINATE_FRAME_DEVICE;
TangoErrorType retval;
// Connect to tango service.
TangoConfig tango_config;
tango_config = TangoService_getConfig(TANGO_CONFIG_DEFAULT);
The Tango header file has an extern "C" wrapper for the C functions and the .o shows them demangled so I can't see why it is failing.
If I comment out...
//tango_config = TangoService_getConfig(TANGO_CONFIG_DEFAULT);
...it compiles and the enums show as locals in the debug so it seems to be a problem with functions: see image of locals here
I may be missing something glaringly obvious because android is fairly new to me. Perhaps someone can test the tangoSDK library with the same code block and spot the issue. It is frustrating that I cannot even link a library. I may be missing something simple but to me it is not obvious.
Any help will be greatly appreciated.
I contacted Sysprogs Support who gave me a link:
PREBUILT_SHARED_LIBRARY syntax
I hadn't realised the library wasn't being copied even though intellisense was reading the header. I needed to include a reference in the make file (android.mk) to copy the library (I copied Tango include and lib folders to the project jni folder):
include $(CLEAR_VARS)
LOCAL_MODULE := tango_client_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_client_api.so
include $(PREBUILT_SHARED_LIBRARY)
I did the same with an additional block for the support library:
include $(CLEAR_VARS)
LOCAL_MODULE := tango_support_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_support_api.so
include $(PREBUILT_SHARED_LIBRARY)
The main module just needs this:
LOCAL_SHARED_LIBRARIES := tango_client_api
The whole file looks like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := tango_client_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_client_api.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := tango_support_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_support_api.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := MoreTeapotsNativeActivity
#VisualGDBAndroid: AutoUpdateSourcesInNextLine
LOCAL_SRC_FILES := gdbserver_launcher.c MoreTeapotsNativeActivity.cpp MoreTeapotsRenderer.cpp
LOCAL_C_INCLUDES := jni/include
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := cpufeatures android_native_app_glue ndk_helper
LOCAL_SHARED_LIBRARIES := tango_client_api
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/ndk_helper)
$(call import-module,android/native_app_glue)
$(call import-module,android/cpufeatures)
I didn't get this to work straight away when following the NDK examples but Sysprogs gave me feedback on my mistake which I will include.
I tried to include:
LOCAL_MODULE_FILENAME := tango_client_api
I left off the lib and .so as seemed to be convention. The .so was not necessary but taking lib off was changing the file name which caused a link error. That said, that line was unnecessary in the first place to I removed it. Then it removed the error relating to this. I have yet to see if the library works at runtime because I now get this error:
java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/com.sample.moreteapots-2/lib/arm64/libMoreTeapotsNativeActivity.so": dlopen failed: library "libbinder.so" not found
But this seems to relate to a problem with Android 7.0 platform 24 and higher where
the system prevents apps from dynamically linking against non-NDK libraries
from /Android/android-sdk/docs/about/versions/nougat/android-7.0-changes.html
I have two native modules to be build as shared library. Both the modules have dependecy on some other common modules.
I am giving the dependecy in Android.mk file using "PREBUILT_SHARED_LIBRARY", but the problem is the libraries specified with "PREBUILT_SHARED_LIBRARY" will get copied to libs/armeabi folder too.. :(
When I include their respective .jars in the main application it throws an eror saying duplicate copy of libraries..
I have to solve this problem by linking the common libraries in ndk build without using "PREBUILT_SHARED_LIBRARY" so that it will not copy the all dependent libraries to libs/areabi.
Can anybody please tell me how can I resolve this problem ? I have googled about this, but everywhere I see the answer use "PREBUILT_SHARED_LIBRARY" to link with already built shared libraries.
Your prebuilt's Android.mk is probably wrong, if you do something like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mygreatlibrary-prebuilt
MY_LIBRARY_NAME := myGreatLibrary
### export include path
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
### path to library
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(MY_LIBRARY_NAME).so
### export dependency on the library
LOCAL_EXPORT_LDLIBS := -L$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/
LOCAL_EXPORT_LDLIBS += -l$(MY_LIBRARY_NAME)
include $(PREBUILT_SHARED_LIBRARY)
Then the correct library will be copied to the correct place
I am trying to write an JNI file and it includes JNIHelp.h, however I met some error:
jni/JNIMPEG4Writer.cpp:4:21: fatal error: JNIHelp.h: No such file or directory
compilation terminated.
I guess I should add something to the Android.mk file, but I am not sure what should I add. This is my Android.mk file:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := JNIMPEG4Writer
LOCAL_STATIC_LIBRARIES := MPEG4Writer
#LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib –llog
LOCAL_SRC_FILES := JNIMPEG4Writer.cpp
include $(BUILD_SHARED_LIBRARY)
Does anyone have any ideas? Thanks!
JNIHelp.h is not part of NDK. You inherited some code from the Android platform. You will find other dependencies on non-public modules, most likely libcutils and libutils.
You have three options: build your code as a module of the platform, rewrite the code to only use public headers and libraries, or download parts of the platform, e.g. https://android.googlesource.com/platform/libnativehelper/, and arrange the include paths accordingly.
To satisfy the linker in the latter scenario, you can use adb pull /system/lib to acquire the versions of libnativehelper.so, libcutils.so, and other referenced non-public libraries. Note that ndk-build will complain about linking against these libraries.
i want to build the expolid code ( https://github.com/revolutionary/zergRush/blob/master/zergRush.c)
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := zergRush
LOCAL_SRC_FILES := zergRush.c
base :=E:\0.Android\system\core
#//base path include the android source code. but i forget the version .maybe 4.0.1
LOCAL_C_INCLUDES :=$(base)/include/
LOCAL_LDLIBS := -llog -lcutils
LOCAL_STATIC_LIBRARIES := libcutils libc
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE_TAGS := eng debug
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
this computer has installed ndk-r9b.
libcutils.so : D:\android-ndk-r9b\platforms\android-19\arch-arm\usr\lib\rs
so i copy it to D:\android-ndk-r9b\platforms\android-19\arch-arm\usr\lib.
default.properties project.properties set target=19
but ndk-build failed .
D:\test\roottest\jni>ndk-build
[armeabi] Compile thumb : zergRush <= zergRush.c
[armeabi] Executable : zergRush
D:/android-ndk-r9b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6
/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lcutils
D:/android-ndk-r9b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6
/../../../../arm-linux-androideabi/bin/ld.exe: D:/test/roottest//obj/local/armeabi/objs/zergRush/zergRush.o: in function
do_fault:D:/test/roottest//jni/zergRush.c:226: error: undefined reference to 'socket_local_client'
D:/android-ndk-r9b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6
/../../../../arm-linux-androideabi/bin/ld.exe: D:/test/roottest//obj/local/armeabi/objs/zergRush/zergRush.o: in function
main:D:/test/roottest//jni/zergRush.c:488: error: undefined reference to 'property_set'
D:/android-ndk-r9b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6
/../../../../arm-linux-androideabi/bin/ld.exe: D:/test/roottest//obj/local/armeabi/objs/zergRush/zergRush.o: in function
main:D:/test/roottest//jni/zergRush.c:619: error: undefined reference to 'property_get'
collect2: ld returned 1 exit status
make.exe: *** [D:/test/roottest//obj/local/armeabi/zergRush] Error 1
i want to know how to include the use-defined libraray path or include libcutils.so and i can make the program . thanks.
The correct syntax in project.properties file is target=android-19. Make sure that you have it that way. If you want to make sure it works, open up your project in Eclipse, right-click on it and select to open its Properties.
Also, you've listed libcutils as both a shared library and a static library in your makefile. libc is also a shared library in Android system, so I'm pretty sure that you ought to do without the entire LOCAL_STATIC_LIBRARIES line.
If fixing the target still does not work, my advice would be to add libcutils.so as a "prebuilt" library (check your <ndk>/docs/PREBUILTS.html file to see how to do that).
Good luck!