You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译AOSP目标aosp_cf_arm64_auto-userdebug时遇OemLock类错误

解决AOSP编译中OemLock类非虚析构器报错问题

错误原因

编译aosp_cf_arm64_auto-userdebug目标时触发该错误,核心原因是cuttlefish::oemlock::OemLock类声明了虚函数,但未定义虚析构函数,而编译配置中开启了-Werror=non-virtual-dtor,将该警告直接升级为错误。

解决方案

方案一:修改源码修复根本问题(推荐)

修改device/google/cuttlefish/host/commands/secure_env/oemlock.h文件,为OemLock类添加虚析构函数:

class OemLock {
public:
    // 保留类中原有的虚函数(例如IsOemLocked等)
    virtual bool IsOemLocked() = 0;
    // 添加虚析构函数,使用默认实现即可
    virtual ~OemLock() = default;
};

添加虚析构符合C++多态类的设计规范,能避免通过基类指针销毁派生类对象时可能出现的内存泄漏问题。

方案二:临时禁用警告(应急使用)

如果暂时不想修改源码,可在对应模块的编译配置中关闭该警告:

  1. 打开device/google/cuttlefish/host/commands/secure_env/Android.bp
  2. 在libsecure_env_linux模块的cppflags中添加-Wno-non-virtual-dtor:
cc_library {
    name: "libsecure_env_linux",
    // 保留其他原有配置
    cppflags: [
        // 保留原有编译flags
        "-Wno-non-virtual-dtor",
    ],
}

注意:此方法仅绕过编译错误,未解决潜在的多态析构问题,不建议长期使用。

关键错误日志

device/google/cuttlefish/host/commands/secure_env/oemlock.h:29:7: error: 'cuttlefish::oemlock::OemLock' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
class OemLock {
^

内容的提问来源于stack exchange,提问作者Ahmed Mohamed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:52:45