Bazel编译Android程序

一、编译C++程序

1、在项目根目录的WROKSPACE文件添加以下配置

python 复制代码
//WORKSPACE文件
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_android_ndk",
    sha256 = "b1a5ddd784e6ed915c2035c0db536a278b5f50c64412128c06877115991391ef",
    strip_prefix = "rules_android_ndk-877c68ef34c9f3353028bf490d269230c1990483",
    url = "https://github.com/bazelbuild/rules_android_ndk/archive/877c68ef34c9f3353028bf490d269230c1990483.zip",
)
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")

android_ndk_repository(
    name = "androidndk",
    path = "/home/client/Documents/program/android-sdk/ndk/25.2.9519653"
)

2、添加BUILD文件,配置源码&平台

配置platform在交叉编译时使用

python 复制代码
//BUILD.bazel文件
cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
)

platform(
    name = "arm64-v8a",
    constraint_values = [
        "@platforms//cpu:arm64",
        "@platforms//os:android",
    ],
)

3、编译源码

bash 复制代码
$ bazel build //main:hello-world --platforms=//main:arm64-v8a
相关推荐
火柴就是我13 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
砖厂小工20 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心20 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心21 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker1 天前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴1 天前
Android17 为什么重写 MessageQueue
android
阿巴斯甜2 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker2 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95272 天前
Andorid Google 登录接入文档
android
黄林晴2 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack