本文主要是介绍Bazel编译Android程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、编译C++程序
1、在项目根目录的WROKSPACE文件添加以下配置
//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在交叉编译时使用
//BUILD.bazel文件
cc_binary(name = "hello-world",srcs = ["hello-world.cc"],
)platform(name = "arm64-v8a",constraint_values = ["@platforms//cpu:arm64","@platforms//os:android",],
)
3、编译源码
$ bazel build //main:hello-world --platforms=//main:arm64-v8a
这篇关于Bazel编译Android程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!