bazelbuild / bazelbuild/rules_android_ndk

toolchain_aarch64-linux-android does not have mandatory providers: 'TemplateVariableInfo' when build android command line programs

Open
#100 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
43
Forks
32
PR merge metrics
No merged PRs in 30d

Description

I'm building an android command line executable which could be run on Android arm64 platform with bazel 8.0 bzlmod method.
But I met below errors with build command "**bazelisk-windows-amd64.exe build //native_hello:native_hello --platforms=//build:android_arm64_platform --verbose_failures**"

> ERROR: D:/bazel/bazel_android_native_demos/native_hello/BUILD:1:10: in toolchains attribute of cc_binary rule //native_hello:native_hello: '@@rules_android_ndk++android_ndk_repository_extension+androidndk//:toolchain_aarch64-linux-android' does not have mandatory providers: 'TemplateVariableInfo'
> ERROR: D:/bazel/bazel_android_native_demos/native_hello/BUILD:1:10: Analysis of target '//native_hello:native_hello' failed
> ERROR: Analysis of target '//native_hello:native_hello' failed; build aborted
> INFO: Elapsed time: 18.648s, Critical Path: 0.15s
> INFO: 1 process: 1 internal.
> ERROR: Build did NOT complete successfully

Are there any compatible issues with cc_binary and bzlmod?
I have searched Google and asked AI tools, but still have no clue.
Please help take a look at this issue.

-----------
My test project structure is as following
```
bazel_android_native_demos
- build/BUILD
- native_hello/
-- BUILD
-- main.cpp
- MODULE.bazel
```

**Contents of MODULE.bazel**
```
module(
name = "bazel_android_native_demos",
version = "1.0",
)

bazel_dep(name = "rules_cc", version = "0.1.0")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_android_ndk", version = "0.1.3")

android_ndk_repository_extension = use_extension(
"@rules_android_ndk//:extension.bzl",
"android_ndk_repository_extension",
)

android_ndk_repository_extension.configure(
path = "C:/Users/Ice3Inch/AppData/Local/Android/Sdk/ndk/25.1.8937393",
api_level = 21,
)

use_repo(android_ndk_repository_extension, "androidndk")

register_toolchains("@androidndk//:all")
```

**Contents of native_hello/BUILD**
```
cc_binary(
name = "native_hello",
srcs = ["main.cpp"],
linkopts = [
"-llog",
],
toolchains = [
"@androidndk//:toolchain_aarch64-linux-android",
],
target_compatible_with = [
"@platforms//cpu:arm64",
"@platforms//os:android",
],
visibility = ["//visibility:public"],
)
```

**Contents of native_hello/main.cpp**
```
#include

int main(int argc, char** argv) {
__android_log_print(ANDROID_LOG_INFO, "NativeHello", "Hello from native code!");
return 0;
}
```

**Contents of build/BUILD**
```
package(default_visibility = ["//visibility:public"])

platform(
name = "android_arm64_platform",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:android",
],
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.