linux - 使用 Android.bp 为 GNU/Linux 系统构建项目

标签 linux makefile android-build build-system

我正在开发一个在Android中运行的命令行工具;但我也想在桌面系统上独立编译和运行它,例如 Ubuntu GNU/Linux 系统。

目前它使用 Android.bp 文件并在 AOSP 中构建。

如何使用 Android.bp 构建 GNU/Linux 系统?

我当然可以将 Android.bp 重写为普通的旧 Makefile,但我不想创建这个额外的代码层来维护。

最佳答案

您可以指定模块应针对哪个目标构建:Android主机两者Host 表示 GNU/Linux(如果您构建 AOSP 的环境就是 GNU/Linux)。

安卓

这是为设备架构构建的典型二进制模块。

cc_binary {
    name: "my-binary",
    srcs: [ "main.cpp" ],
    shared_libs: [ "libcutils" ]
}

主机

有多种_host模块类型(例如cc_binary_hostcc_test_hostjava_binary_host)可以创建主机二进制文件.

cc_binary_host {
    name: "my-binary-host",
    srcs: [ "main.cpp" ],
    shared_libs: [ "libcutils" ]
}

两者

如果您想同时构 build 备二进制文件和主机二进制文件,则可以使用 host_supported: true

cc_binary {
    name: "my-binary",
    srcs: [ "main.cpp" ],
    shared_libs: [ "libcutils" ],
    host_supported: true
}

您可能想要为 androidhost 指定其他标志、定义、源等。您可以使用 target 属性来做到这一点:

cc_binary {
    name: "my-binary",
    srcs: [ "main.cpp" ],
    shared_libs: [ "libcutils" ],
    host_supported: true,

    target: {
        android: {
            // android specific properties
        },
        host: {
            // host-side specific properties
        }
    }
}

关于模块依赖项的说明

同一目标需要支持另一个模块所依赖的每个模块。

示例:cc_binary_host 不能依赖 host_supported: falsecc_library

关于linux - 使用 Android.bp 为 GNU/Linux 系统构建项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57983735/

相关文章:

php - 如何自动上传更改?

c++ - 类对象在 int main() 中是 'undefined'

gradle - 安卓 : run sonarRunner from gradle

linux - 在不修改代码的情况下测量函数执行时间

linux - Bourne Shell (bin/sh) 中的嵌套变量

windows - dmake 中的 shell 命令添加 '/S'

android - 如何构建Android版本?

android - 构建错误: Execution failed for task ':app:transformNativeLibsWithStripDebugSymbolForDebug

c - linux编程: write to device file

c++ - Code::Blocks 没有制作目标文件