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
相关推荐
修炼者1 天前
Android Studio的技巧
android·android studio
雨白1 天前
ARouter 入门指南:从基本跳转到对象传递
android
用户69371750013841 天前
17.Kotlin 类:类的形态(四):枚举类 (Enum Class)
android·后端·kotlin
h***34631 天前
MS SQL Server 实战 排查多列之间的值是否重复
android·前端·后端
用户69371750013841 天前
16.Kotlin 类:类的形态(三):密封类 (Sealed Class)
android·后端·kotlin
摆烂积极分子1 天前
安卓开发学习-安卓版本
android·学习
n***26561 天前
MySQL JSON数据类型全解析(JSON datatype and functions)
android·mysql·json
t***82111 天前
mysql的主从配置
android·mysql·adb
YF02111 天前
Frida如何稳定连接PC端跟Android手机端
android·mac·xposed
O***P5711 天前
【MySQL】MySQL内置函数--日期函数字符串函数数学函数其他相关函数
android·mysql·adb