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
相关推荐
Android系统攻城狮1 小时前
Android tinyalsa深度解析之pcm_params_get_periods_min调用流程与实战(一百七十三)
android·pcm·tinyalsa·音频进阶手册
Xempastissimo2 小时前
Android常见界面控件
android
法欧特斯卡雷特2 小时前
从 Kotlin 编译器 API 的变化开始: 2.3.20
android·后端·开源
词元Max3 小时前
1.5 Harness 架构深度解析:Claude Code 为什么强?
android·架构
yy55273 小时前
Mysql 主从复制与读写分离
android·数据库·mysql
zhenxin01224 小时前
万字详解 MySQL MGR 高可用集群搭建
android·mysql·adb
做萤石二次开发的哈哈4 小时前
萤石云硬件接入如何完成云对讲套件低代码集成?
android·低代码·rxjava
恋猫de小郭5 小时前
2026 AI 时代下,Flutter 和 Dart 的机遇和未来发展,AI 一体化
android·前端·flutter
缺土的鲨鱼辣椒6 小时前
Android 资源类型概述
android
sp426 小时前
安卓原生 MQTT 通讯 Java 实现
android