参考在android P上添加HIDL模块编译报错error: VNDK library list has been changed_IV24KC的博客-优快云博客
Android HIDL 介绍学习和实战应用_Super Jang的博客-优快云博客
Android8.1HAL层开发_他叫小黑的博客-优快云博客
Android11添加AIDL系统服务及HIDL接口服务_hidl接口添加_凯文的内存的博客-优快云博客
1在hardware/interfaces创建文件夹
caron
1.0
default
ICaron.hal
并修改权限
执行./hardware/interfaces/update-makefiles.sh
生成Android.bp
执行hidl-gen -L c++-impl -o ./hardware/interfaces/caron/1.0/default/ -r caron.hardware:./hardware/interfaces android.hardware.caron@1.0
生成default下的.cpp .h
执行hidl-gen -L androidbp-impl -o ./hardware/interfaces/caron/1.0/default/ -r caron.hardware:./hardware/interfaces android.hardware.caron@1.0
生成default下的Android.bp
生成hash
wuyu@ubuntu:~/wuyu_share/android11$ hidl-gen -L hash -r android.hardware:hardware/interfaces -r android.hidl:system/libhidl/transport android.hardware.caron@1.0
4aa74220f6076f22cdc4c6ec593b934190fdb1cff0116cab03211b34baa0a48b android.hardware.caron@1.0::ICaron
目录结构如下
+-- 1.0
¦ +-- default
¦ ¦ +-- Android.bp
¦ ¦ +-- Caron.cpp
¦ ¦ +-- Caron.h
¦ +-- ICaron.hal
| +-- Android.bp
default下文件
Android.bp
// FIXME: your file license if you have one
cc_library_shared {
name: "android.hardware.caron@1.0-impl",
relative_install_path: "hw",
proprietary: true,
defaults: ["hidl_defaults"],
srcs: ["Caron.cpp",],
shared_libs: [
"libcutils",
"liblog",
"libhidlbase",
"libhardware",
"libutils",
"android.hardware.caron@1.0",
],
}
cc_binary {
vendor: true,
relative_install_path: "hw",
defaults: ["hidl_defaults"],
name: "android.hardware.caron@1.0-service",
init_rc: ["android.hardware.caron@1.0-service.rc"],
vintf_fragments: ["android.hardware.caron@1.0-service.xml"],
srcs: ["Caron.cpp",
"service.cpp",],
shared_libs: [
"libcutils",
"liblog",
"libhidlbase",
"libhardware",
"libutils",
"android.hardware.caron@1.0",
],
}
Caron.cpp
// FIXME: your file license if you have one
#include "Caron.h"
namespace android::hardware::caron::implementation {
// Methods from ::android::hardware::caron::V1_0::ICaron follow.
Return<void> Caron::helloWorld(const hidl_string& name, helloWorld_cb _hidl_cb) {
// TODO implement
char buf[512];
memset(buf, 0, sizeof(buf));
snprintf(buf, 512, "hello world, %s", name.c_str());
hidl_string result(buf);
_hidl_cb(result);
return Void();
}
}// Methods from ::android
Caron.h
// FIXME: your file license if you have one
#pragma once
#include <android/hardware/caron/1.0/ICaron.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
namespace android::hardware::caron::implementation {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
struct Caron : public V1_0::ICaron {
// Methods from ::android::hardware::caron::V1_0::ICaron follow.
Return<void> helloWorld(const hidl_string& name, helloWorld_cb _hidl_cb) override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
};
// FIXME: most likely delete, this is only for passthrough implementations
// extern "C" ICaron* HIDL_FETCH_ICaron(const char* name);
} // namespace android::hardware::caron::implementation
default下添加
android.hardware.caron@1.0-service.rc
service vendor.caron-hal-1-0 /vendor/bin/hw/android.hardware.caron@1.0-service
interface android.hardware.caron@1.0::ICaron default
class hal
user system
group system
service.cpp
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "android.hardware.caron@1.0-service"
#include <android/log.h>
#include <hidl/HidlSupport.h>
#include <hidl/HidlTransportSupport.h>
#include <android/hardware/caron/1.0/ICaron.h>
#include <hidl/LegacySupport.h>
#include "Caron.h"
using android::hardware::caron::V1_0::ICaron;
using android::hardware::caron::implementation::Caron;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::sp;
//using android::hardware::defaultPassthroughServiceImplementation;
int main() {
#if 0
return defaultPassthroughServiceImplementation<ICaron>();
//passthrough mode
#else
configureRpcThreadpool(4, true);
sp<ICaron> caron = new Caron();
if (caron != nullptr) {
if (::android::OK != caron->registerAsService()) {
return 1;
}
} else {
ALOGE("Can't create instance of BiometricsFingerprint, nullptr");
}
joinRpcThreadpool();
return 0; // joinRpcThreadpool shouldn't exit
#endif
}
编译
FAILED: out/target/product/sp7731e_1h10/obj/PACKAGING/vndk_intermediates/check-list-timestamp
/bin/bash -c "(( diff --old-line-format=\"Removed %L\" --new-line-format=\"Added %L\" --unchanged-line-format=\"\" build/make/target/product/gsi/30.txt out/soong/vndk/vndk.libraries.txt || ( echo -e \" error: VNDK library list has been changed.\\n\" \" Changing the VNDK library list is not allowed in API locked branches.\"; exit 1 )) ) && (mkdir -p out/target/product/sp7731e_1h10/obj/PACKAGING/vndk_intermediates/ ) && (touch out/target/product/sp7731e_1h10/obj/PACKAGING/vndk_intermediates/check-list-timestamp )"
Added VNDK-core: android.hardware.caron@1.0.so
报错 build/make/target/product/gsi/30.txt out/soong/vndk/vndk.libraries.txt文件不相同
修改成一致添加VNDK-core: android.hardware.caron@1.0.so