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

如何将原生C应用整合到自定义LineageOS 21 ROM中?

解决LineageOS 21模拟器ROM整合原生C应用的编译错误

问题背景

已在Ubuntu 20.04成功编译LineageOS 21模拟器ROM,步骤如下:

cd lineageos
source build/envsetup.sh
breakfast sdk_phone_x86_64
mka

为将原生C应用helloworld整合进ROM,已完成:

  1. 在external/helloworld目录创建helloworld.c:
/* external/helloworld/helloworld.c */
#include <stdio.h>  

int main() {  
    printf("Hello, World!\n");  
    return 0;  
}  
  1. 创建Android.bp蓝图文件:
cc_binary {  
    name: "helloworld",  
    srcs: ["helloworld.c"],  
    installable: true,  
    relative_install_path: "bin",  
}  

尝试修改device/generic/goldfish/product/generic.mk,添加PRODUCT_PACKAGES += helloworld后执行编译,触发错误:

build/make/core/artifact_path_requirements.mk:31: warning: vendor/lineage/build/target/product/lineage_sdk_phone_x86_64.mk produces files inside build/make/target/product/generic_system.mks artifact path requirement.
Offending entries:
system/bin/helloworld
In file included from build/make/core/main.mk:1433:
build/make/core/artifact_path_requirements.mk:31: error: Build failed.

错误原因

LineageOS构建系统对system分区的核心路径(如system/bin)有严格权限校验,generic_system.mk定义了仅允许特定组件写入这些路径,自定义应用直接写入会触发路径校验失败。

正确解决步骤

1. 调整应用安装路径

修改external/helloworld/Android.bp,将安装路径改为非核心校验路径(如xbin或vendor/bin):

cc_binary {  
    name: "helloworld",  
    srcs: ["helloworld.c"],  
    installable: true,  
    relative_install_path: "xbin",  // 可选:vendor/bin
}  

2. 选择LineageOS专属配置文件添加应用

不要修改原生AOSP的generic.mk,而是编辑LineageOS针对模拟器的产品配置文件,例如vendor/lineage/build/target/product/lineage_sdk_phone_x86_64.mk,在文件末尾添加:

PRODUCT_PACKAGES += helloworld

若上述文件不存在,可查找对应模拟器的Lineage产品配置文件(通常在vendor/lineage/build/target/product/或device/generic/goldfish/product/目录下)。

3. 重新编译

无需执行全量清理,先单独编译应用验证,再进行全ROM编译:

source build/envsetup.sh
breakfast sdk_phone_x86_64
mka helloworld  # 单独编译应用,确认无错误
mka

验证方法

编译完成后启动模拟器,通过ADB shell执行应用:

adb shell
# 若安装在xbin
/system/xbin/helloworld
# 若安装在vendor/bin
/vendor/bin/helloworld

正常情况下会输出Hello, World!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 06:25:56