我在 Android 的 healthd 中添加了一些代码,包括一个文件“client.cpp”,它使用libjsoncpp
.
我在 Android 构建期间看到以下错误:
FAILED: out/soong/.intermediates/system/core/healthd/healthd/android_arm64_armv8-a_cortex-a53_core/unstripped/healthd
prebuilts/clang/host/linux-x86/clang-r353983c/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_dynamic/android_arm64_armv8-a_cortex-a53_core/crtbegin_dynamic.o @out/soong/.intermediates/system/core/healthd/healthd/android_arm64_armv8-a_cortex-a53_core/unstripped/healthd.rsp out/soong/.intermediates/hardware/interfaces/health/2.0/utils/libhealthservice/libhealthservice/android_arm64_armv8-a_cortex-a53_core_static/libhealthservice.a out/soong/.intermediates/hardware/interfaces/health/2.0/default/android.hardware.health@2.0-impl/android_arm64_armv8-a_cortex-a53_core_static/android.hardware.health@2.0-impl.a out/soong/.intermediates/hardware/interfaces/health/1.0/default/android.hardware.health@1.0-convert/android_arm64_armv8-a_cortex-a53_core_static/android.hardware.health@1.0-convert.a out/soong/.intermediates/hardware/interfaces/health/2.0/utils/libhealthstoragedefault/libhealthstoragedefault/android_arm64_armv8-a_cortex-a53_core_static/libhealthstoragedefault.a out/soong/.intermediates/system/core/healthd/libbatterymonitor/android_arm64_armv8-a_cortex-a53_core_static/libbatterymonitor.a -Wl,--start-group prebuilts/clang/host/linux-x86/clang-r353983c/lib64/clang/9.0.3/lib/linux/libclang_rt.builtins-aarch64-android.a prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/lib64/libatomic.a out/soong/.intermediates/build/soong/libgcc_stripped/android_arm64_armv8-a_cortex-a53_core_static/libgcc_stripped.a -Wl,--end-group out/soong/.intermediates/system/core/base/libbase/android_arm64_armv8-a_cortex-a53_core_shared/libbase.so out/soong/.intermediates/system/core/libcutils/libcutils/android_arm64_armv8-a_cortex-a53_core_shared/libcutils.so out/soong/.intermediates/system/libhidl/libhidlbase/android_arm64_armv8-a_cortex-a53_core_shared/libhidlbase.so out/soong/.intermediates/system/libhidl/libhidltransport/android_arm64_armv8-a_cortex-a53_core_shared/libhidltransport.so out/soong/.intermediates/system/libhwbinder/libhwbinder/android_arm64_armv8-a_cortex-a53_core_shared/libhwbinder.so out/soong/.intermediates/system/core/liblog/liblog/android_arm64_armv8-a_cortex-a53_core_shared/liblog.so out/soong/.intermediates/system/core/libutils/libutils/android_arm64_armv8-a_cortex-a53_core_shared/libutils.so out/soong/.intermediates/hardware/interfaces/health/2.0/android.hardware.health@2.0/android_arm64_armv8-a_cortex-a53_core_shared/android.hardware.health@2.0.so out/soong/.intermediates/hardware/interfaces/health/1.0/android.hardware.health@1.0/android_arm64_armv8-a_cortex-a53_core_shared/android.hardware.health@1.0.so out/soong/.intermediates/external/libcxx/libc++/android_arm64_armv8-a_cortex-a53_core_shared/libc++.so out/soong/.intermediates/bionic/libc/libc/android_arm64_armv8-a_cortex-a53_core_shared_10000/libc.so out/soong/.intermediates/bionic/libm/libm/android_arm64_armv8-a_cortex-a53_core_shared_10000/libm.so out/soong/.intermediates/bionic/libdl/libdl/android_arm64_armv8-a_cortex-a53_core_shared_10000/libdl.so out/soong/.intermediates/bionic/libc/crtend_android/android_arm64_armv8-a_cortex-a53_core/obj/bionic/libc/arch-common/bionic/crtend.o -o out/soong/.intermediates/system/core/healthd/healthd/android_arm64_armv8-a_cortex-a53_core/unstripped/healthd -target aarch64-linux-android -Bprebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_stripped.a -fuse-ld=lld -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags -Wl,--no-undefined -Wl,--hash-style=gnu -Wl,--icf=safe -Wl,-z,max-page-size=4096 -Wl,--fix-cortex-a53-843419 -pie -nostdlib -Bdynamic -Wl,--gc-sections -Wl,-z,nocopyreloc prebuilts/clang/host/linux-x86/clang-r353983c/lib64/clang/9.0.3/lib/linux/libclang_rt.ubsan_minimal-aarch64-android.a -Wl,--exclude-libs,libclang_rt.ubsan_minimal-aarch64-android.a -Wl,-execute-only -Wl,-dynamic-linker,/system/bin/linker64
ld.lld: error: undefined symbol: Json::Value::Value(Json::ValueType)
>>> referenced by client.cpp:19 (hardware/interfaces/health/2.0/default/client.cpp:19)
>>> client.o:(Client::parse_line(char*)) in archive out/soong/.intermediates/hardware/interfaces/health/2.0/default/android.hardware.health@2.0-impl/android_arm64_armv8-a_cortex-a53_core_static/android.hardware.health@2.0-impl.a
ld.lld: error: undefined symbol: Json::Reader::Reader()
>>> referenced by client.cpp:20 (hardware/interfaces/health/2.0/default/client.cpp:20)
>>> client.o:(Client::parse_line(char*)) in archive out/soong/.intermediates/hardware/interfaces/health/2.0/default/android.hardware.health@2.0-impl/android_arm64_armv8-a_cortex-a53_core_static/android.hardware.health@2.0-impl.a
...
我已添加libjsoncpp
到以下shared_libs
部分hardware/interfaces/health/2.0/defaultAndroid.bp
:
cc_defaults {
name: "android.hardware.health@2.0-impl_defaults",
recovery_available: true,
cflags: [
"-Wall",
"-Werror",
"-std=gnu++17",
],
shared_libs: [
"libbase",
"libhidlbase",
"libhidltransport",
"libhwbinder",
"liblog",
"libutils",
"libcutils",
"android.hardware.health@2.0",
"libjsoncpp",
],
static_libs: [
"libbatterymonitor",
"android.hardware.health@1.0-convert",
],
}
// Helper library for implementing health HAL. It is recommended that a health
// service or passthrough HAL link to this library.
cc_library_static {
name: "android.hardware.health@2.0-impl",
defaults: ["android.hardware.health@2.0-impl_defaults"],
vendor_available: true,
srcs: [
"Health.cpp",
"healthd_common.cpp",
"powerd.cpp",
"client.cpp",
],
export_include_dirs: ["include"],
}
// Default passthrough implementation for recovery. Vendors can implement
// android.hardware.health@2.0-impl-recovery-<device> to customize the behavior
// of the HAL in recovery.
// The implementation does NOT start the uevent loop for polling.
cc_library_shared {
name: "android.hardware.health@2.0-impl-default",
defaults: ["android.hardware.health@2.0-impl_defaults"],
recovery_available: true,
relative_install_path: "hw",
static_libs: [
"android.hardware.health@2.0-impl",
"libhealthstoragedefault",
],
srcs: [
"HealthImplDefault.cpp",
],
}
我已经成功地提供了 libjsoncpp 的头文件。直到我添加了实际使用的代码libjsoncpp
,我才看到这个错误。
该库确实作为先前构建的 Android 映像的一部分存在:
smarc_mx8mq:/ # find / -name "libjsoncpp*" 2>/dev/null
/system/lib64/libjsoncpp.so
/system/lib64/vndk-sp-29/libjsoncpp.so
/system/lib/vndk-sp-29/libjsoncpp.so
我如何告诉 Android 我想libjsoncpp
链接到healthd
?
它甚至不应该在执行之前尝试解析这些符号healthd
,因为它们是由共享库提供的。
更新:
我注意到其中的其他库shared_libs
都存在于命令行中,如.so
s,但libjsoncpp
丢失了。
新问题是为什么libcppjson
链接命令中缺少?