bazelbuild / rules_android_ndk

Apache License 2.0
32 stars 15 forks source link

Building with `--android_platforms=//:arm64` returns error. #65

Open AnDevi opened 8 months ago

AnDevi commented 8 months ago

I'm using bazel 7.0.2 right now. Compilation with command: bazel build //apps/playground-android --fat_apk_cpu=arm64-v8a --android_crosstool_top=@androidndk//:toolchain --noincompatible_enable_android_toolchain_resolution works fine.

But I'd like to build it with command: bazel build //apps/playground-android --android_platforms=//apps/playground-android:android_arm64_platform android_arm64_platform is defined like that:

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

but unfortunately this command returns an error:

/private/var/tmp/_bazel_user/76f838fa12f5ea48d0b75f7268fa8d25/external/bazel_tools/tools/cpp/BUILD:58:19: in cc_toolchain_alias rule @@bazel_tools//tools/cpp:current_cc_toolchain: 
Traceback (most recent call last):
        File "/virtual_builtins_bzl/common/cc/cc_toolchain_alias.bzl", line 26, column 48, in _impl
        File "/virtual_builtins_bzl/common/cc/cc_helper.bzl", line 219, column 17, in _find_cpp_toolchain
Error in fail: Unable to find a CC toolchain using toolchain resolution. Target: @@bazel_tools//tools/cpp:current_cc_toolchain, Platform: @@//apps/playground-android:android_arm64_platform, Exec platform: @@local_config_platform//:host
ERROR: /private/var/tmp/_bazel_user/76f838fa12f5ea48d0b75f7268fa8d25/external/bazel_tools/tools/cpp/BUILD:58:19: Analysis of target '@@bazel_tools//tools/cpp:current_cc_toolchain' failed
ERROR: Analysis of target '//apps/playground-android:playground-android' failed; build aborted: Analysis failed

My WORKSPACE file looks like that (path to ANDROID_NDK_HOME is specified in env varaible) :

http_archive(
    name = "rules_android_ndk",
    sha256 = "b29409496439cdcdb50a8e161c4953ca78a548e16d3ee729a1b5cd719ffdacbf",
    strip_prefix = "rules_android_ndk-81ec8b79dc50ee97e336a25724fdbb28e33b8d41",
    url = "https://github.com/bazelbuild/rules_android_ndk/archive/81ec8b79dc50ee97e336a25724fdbb28e33b8d41.zip",
)

load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")

android_ndk_repository(
    name = "androidndk",
    api_level = 33,
)

register_toolchains("@androidndk//:all")

Am I missing something in command or in my configuration ? Or what else could be problematic ?

ted-xie commented 4 months ago

@AnDevi I think this has been fixed in the latest commits in this repo.

rules_android_ndk/examples/basic$ bazelisk build java/com/app --android_platforms=//:arm64-v8a
INFO: Analyzed target //java/com/app:app (276 packages loaded, 26221 targets configured).
INFO: Found 1 target...
Target //java/com/app:app up-to-date:
  bazel-bin/java/com/app/app_deploy.jar
  bazel-bin/java/com/app/app_unsigned.apk
  bazel-bin/java/com/app/app.apk
INFO: Elapsed time: 4.034s, Critical Path: 1.15s
INFO: 7 processes: 1 internal, 6 linux-sandbox.
INFO: Build completed successfully, 7 total actions

rules_android_ndk/examples/basic$ cat BUILD.bazel 
platform(
    name = "arm64-v8a",
    constraint_values = [
        "@platforms//cpu:arm64",
        "@platforms//os:android",
    ],
)

platform(
    name = "x86",
    constraint_values = [
        "@platforms//cpu:x86_32",
        "@platforms//os:android",
    ],
)

I built this with rules_android_ndk commit b91e64f9135cbb7705d443a8af23832d01b4bfe2, Bazel 7.2.1, NDK r25c.