HIDL学习

在AndroidP上添加HIDL模块时遇到编译错误,提示VNDKlibrary列表已更改。错误发生在API锁定分支中改变VNDK库列表是不允许的。解决方法是更新VNDK-core列表,添加android.hardware.caron@1.0.so到相应文件使其保持一致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考在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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值