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
相关推荐
小镇学者6 小时前
【PHP】导入excel 报错Trying to access array offset on value of type int
android·php·excel
一笑的小酒馆9 小时前
Android11 Launcher3去掉抽屉改为单层
android
louisgeek11 小时前
Git 根据不同目录设置不同账号
android
qq_3909347412 小时前
MySQL中的系统库(简介、performance_schema)
android·数据库·mysql
whysqwhw13 小时前
Kotlin Flow 实现响应式编程指南
android
二流小码农13 小时前
鸿蒙开发:一文了解桌面卡片
android·ios·harmonyos
每次的天空13 小时前
Android第十七次面试总结(Java数据结构)
android·java·面试
梁同学与Android13 小时前
Android --- Handler的用法,子线程中怎么切线程进行更新UI
android·handler·子线程更新ui·切换到主线程
Fastcv13 小时前
这TextView也太闪了,咋做的?
android
恋猫de小郭13 小时前
iOS 26 beta1 重新禁止 JIT 执行,Flutter 下的 iOS 真机 hot load 暂时无法使用
android·前端·flutter