Skip to content

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

@Ice3Inch

Description

@Ice3Inch

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 <android/log.h>

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",
    ],
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions