首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定义和实现HIDL接口

定义和实现HIDL接口
EN

Stack Overflow用户
提问于 2020-04-22 11:08:33
回答 2查看 3K关注 0票数 3

出于测试目的,我希望创建一个HIDL接口+实现,并以系统服务的形式运行这个组合。为此,我定义了IGuotie.hal接口:

代码语言:javascript
复制
package android.hardware.guotie@2.0;

interface IGuotie {
    add(int32_t i, int32_t k) generates (int32_t result);
};

下面的文件用于实现接口

Guotie.h

代码语言:javascript
复制
#pragma once

#include <android/hardware/guotie/2.0/IGuotie.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>

namespace android {
namespace hardware {
namespace guotie {
namespace V2_0 {
namespace 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 Guotie : public IGuotie {
    // Methods from ::android::hardware::guotie::V2_0::IGuotie follow.
    Return<int32_t> add(int32_t i, int32_t k) override;

    // Methods from ::android::hidl::base::V1_0::IBase follow.
   static IGuotie* getInstance(void); 
};

}  // namespace implementation
}  // namespace V2_0
}  // namespace guotie
}  // namespace hardware
} 

Guotie.cpp

代码语言:javascript
复制
#include "Guotie.h"

namespace android {
namespace hardware {
namespace guotie {
namespace V2_0 {
namespace implementation {

// Methods from ::android::hardware::guotie::V2_0::IGuotie follow.
Return<int32_t> Guotie::add(int32_t i, int32_t k) {
    return i + k;
}

IGuotie *Guotie::getInstance(void) {
    return new Guotie();
}

}  // namespace implementation
}  // namespace V2_0
}  // namespace guotie
}  // namespace hardware
} 

service.cpp

代码语言:javascript
复制
#define LOG_TAG "android.hardware.graphics.allocator@2.0-service"

#include <android/hardware/guotie/2.0/IGuotie.h>

#include <hidl/LegacySupport.h>

#include "Guotie.h"

using android::hardware::guotie::V2_0::IGuotie;
using android::hardware::guotie::V2_0::implementation::Guotie;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::sp;

int main() {
      int res;
      android::sp<IGuotie> ser = Guotie::getInstance();
      ALOGE("simp main");
      configureRpcThreadpool(1, true /*callerWillJoin*/);

      if (ser != nullptr) {
          res = ser->registerAsService();
          if(res != 0)
            ALOGE("Can't register instance of GuotieHardware, nullptr");
      } else {
          ALOGE("Can't create instance of GuotieHardware, nullptr");
       }

      joinRpcThreadpool();

      return 0; // should never get here
}

android.hardware.guotie@2.0-service.rc

代码语言:javascript
复制
service guotieserver /vendor/bin/hw/android.hardware.guotie@2.0-service
    class hal
    user root
    group root
    seclabel u:r:su:s0

Android.bp

代码语言:javascript
复制
hidl_interface {
    name: "android.hardware.guotie@2.0",
    root: "android.hardware",
    vndk: {
        enabled: true,
    },
    srcs: [
        "IGuotie.hal",
    ],
    interfaces: [
        "android.hidl.base@1.0",
    ],
    gen_java: true,
}

生成导致以下错误消息的结果

代码语言:javascript
复制
FAILED: out/target/product/generic/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/29.txt out/target/product/generic/obj/PACKAGING/vndk_intermediates/libs.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/generic/obj/PACKAGING/vndk_intermediates/ ) && (touch out/target/product/generic/obj/PACKAGING/vndk_intermediates/check-list-timestamp )"
Removed VNDK-code: android.hardware.guotie@2.0.so
Added VNDK-core: android.hardware.guotie@2.0.so
 error: VNDK library list has been changed.
        Changing the VNDK library list is not allowed in API locked branches.

有些文章建议将android.hardware.guotie@2.0.so添加到build/make/target/product/vndk/28.txt中(在我的例子中)。但是,vndk文件夹不存在。相反,我将其添加到build/make/target/product/gsi/29.txtcurrent.txt中,但构建仍然失败(按字母顺序添加)。有什么建议吗?

EN

回答 2

Stack Overflow用户

发布于 2020-05-13 14:00:06

android.hardware添加界面通常是由谷歌自己完成的。供应商HIDL接口不是VNDK的一部分。

您可能应该将自己视为供应商,并将此部分从Android.bp中删除。

代码语言:javascript
复制
vndk: {
    enabled: true,
},

并将命名空间更改为vendor.<you>.guotie

有关VNDK是什么的更多信息,请参见正式文档:https://source.android.com/devices/architecture/vndk

票数 1
EN

Stack Overflow用户

发布于 2021-01-27 17:10:39

当我试图制作Khadas vim3安卓P时,解决了这个构建错误。

首先,请检查out/target/product/product_name/obj/PACKAGING/vndk_intermediates/libs.txt是否与、build\make\target\product\28.txt和\current.txt相同。

其次,请运行做出更新-api.

这对我有用,希望我的分享能对你有所帮助。

你可以在我的 GitHub上看到更多细节和我的控制台截图:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61363638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档