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
相关推荐
怪兽20141 小时前
Android View, SurfaceView, GLSurfaceView 的区别
android·面试
龚礼鹏1 小时前
android 图像显示框架二——流程分析
android
消失的旧时光-19431 小时前
kmp需要技能
android·设计模式·kotlin
帅得不敢出门2 小时前
Linux服务器编译android报no space left on device导致失败的定位解决
android·linux·服务器
雨白3 小时前
协程间的通信管道 —— Kotlin Channel 详解
android·kotlin
TimeFine5 小时前
kotlin协程 容易被忽视的CompletableDeferred
android
czhc11400756636 小时前
Linux1023 mysql 修改密码等
android·mysql·adb
GOATLong7 小时前
MySQL内置函数
android·数据库·c++·vscode·mysql
onthewaying8 小时前
Android SurfaceTexture 深度解析
android·opengl
茄子凉心8 小时前
Android Bluetooth 蓝牙通信
android·蓝牙通信·bluetooth通信