Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Platforms does not work with AAR Import #21225

Closed
ankit-agarwal-ai opened this issue Feb 6, 2024 · 5 comments
Closed

Android Platforms does not work with AAR Import #21225

ankit-agarwal-ai opened this issue Feb 6, 2024 · 5 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug

Comments

@ankit-agarwal-ai
Copy link
Contributor

ankit-agarwal-ai commented Feb 6, 2024

Description of the bug:

Hi, all.

We recently upgraded to bazel 7.0.2 which according to this post, enabled android platforms for use: https://blog.bazel.build/2023/11/15/android-platforms.html

I am cross compiling android apps with the following bazel rc flags:

common --incompatible_enable_android_toolchain_resolution
common --android_platforms=//:arm64_android_ndk
build --@io_bazel_rules_kotlin//kotlin/settings:jvm_emit_jdeps=False

I am noticing an issue with a maven dependency:

        "com.github.gkonovalov.android-vad:webrtc:2.0.6",

This command below:


cd /home/ankit/.cache/bazel/_bazel_ankit/7bf1254182ebae36d2817c38fe27106c/sandbox/linux-sandbox/7401/execroot/mosaic && \
  exec env - \
    GTEST_COLOR=1 \
    INVALIDATE_BAZEL_CACHE_COUNTER=4 \
    PATH=/bin:/usr/bin:/usr/local/bin \
    TMPDIR=/tmp \
  /home/ankit/.cache/bazel/_bazel_ankit/install/14fb027596f626f2526df4873ea20b8b/linux-sandbox -t 15 -w /dev/shm -w /home/ankit/.cache/bazel/_bazel_ankit/7bf1254182ebae36d2817c38fe27106c/sandbox/linux-sandbox/7401/execroot/mosaic -w /opt/.qnx -w /tmp -e /tmp -S /home/ankit/.cache/bazel/_bazel_ankit/7bf1254182ebae36d2817c38fe27106c/sandbox/linux-sandbox/7401/stats.out -N -D /home/ankit/.cache/bazel/_bazel_ankit/7bf1254182ebae36d2817c38fe27106c/sandbox/linux-sandbox/7401/debug.out -- bazel-out/linux_x86_64_platform-opt-exec/bin/external/bazel_tools/tools/android/aar_native_libs_zip_creator --input_aar external/maven/v1/https/jitpack.io/com/github/gkonovalov/android-vad/webrtc/2.0.6/webrtc-2.0.6.aar --cpu k8 --output_zip bazel-out/arm64_android_ndk-fastbuild-android-ST-8b67b3e599b1/bin/external/maven/_aar/com_github_gkonovalov_android_vad_webrtc/native_libs.zip

fails to compile with the following error;

AAR external/maven/v1/https/jitpack.io/com/github/gkonovalov/android-vad/webrtc/2.0.6/webrtc-2.0.6.aar missing native libs for requested architecture: k8

It looks like the offending line is the --cpu k8, and indeed when I cd'd into the bazel sandbox and ran the command with --cpu arm64-v8a it ran without error. I tracked down the offending line to:

.add("--cpu", ruleContext.getConfiguration().getCpu())

My code does work with the following bazelrc and platform mappings flags (e.g we have a workaround)

common --noincompatible_enable_android_toolchain_resolution
build --platform_mappings=tools/build/bazel.rc.d/platform_mappings
build --fat_apk_cpu arm64-v8a
# Uncomment the below lines to build for x86
# build --fat_apk_cpu x86_64
build --android_crosstool_top=@androidndk//:toolchain
build --@io_bazel_rules_kotlin//kotlin/settings:jvm_emit_jdeps=False

Platform mappings

flags:
    # Android
    # Mostly, native code is compiled after the android_binary rule has run a transition to compile for that platform.
    # We just detect the transition, which sets "Android configuration distinguisher", and then translate the CPU it set.
    --Android configuration distinguisher=android
    --cpu=arm64-v8a
        //:arm64_android_ndk
    --Android configuration distinguisher=android
    --cpu=x86_64
        //:x86_64_android_ndk

We're hoping to get rid of this code soon, so wondering if I am missing something here.

We actually ran into this when we were on a bazel 7 pre-release and reported an issue here: bazelbuild/rules_android_ndk#39

Thanks in advance!

Which category does this issue belong to?

Android

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

On bazel 7, use android platforms, and attempt to compile the maven dependency:

        "com.github.gkonovalov.android-vad:webrtc:2.0.6",

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 7.0.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

Not a public repo

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

I don't think this is a regression

Have you found anything relevant by searching the web?

We actually ran into this when we were on a bazel 7 pre-release and reported an issue here: bazelbuild/rules_android_ndk#39

Any other information, logs, or outputs that you want to share?

No response

@github-actions github-actions bot added the team-Android Issues for Android team label Feb 6, 2024
@ted-xie ted-xie added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Feb 20, 2024
@ted-xie
Copy link
Contributor

ted-xie commented Feb 20, 2024

We'll address this in the Starlark version of aar_import in rules_android.

@ted-xie
Copy link
Contributor

ted-xie commented Feb 21, 2024

Since Bazel 7.1.0 is around the corner, I think we can actually get this into the upcoming release.

@ankit-agarwal-ai
Copy link
Contributor Author

Would be great if this was CP'd onto the release! Thanks for the timely fix :)

@fmeum
Copy link
Collaborator

fmeum commented Feb 27, 2024

@bazel-io fork 7.1.0

bazel-io pushed a commit to bazel-io/bazel that referenced this issue Feb 27, 2024
Fixes bazelbuild#21225

PiperOrigin-RevId: 610551472
Change-Id: I7e62919dd41d0d4e2b923df1942920162f554809
github-merge-queue bot pushed a commit that referenced this issue Feb 27, 2024
…21502)

Fixes #21225

Commit
1e77944

PiperOrigin-RevId: 610551472
Change-Id: I7e62919dd41d0d4e2b923df1942920162f554809

Co-authored-by: Googler <[email protected]>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.1.0 RC2. Please test out the release candidate and report any issues as soon as possible.
If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=7.1.0rc2. Thanks!

copybara-service bot pushed a commit to bazelbuild/rules_android that referenced this issue Apr 2, 2024
…tforms and toolchain resolution.

This mirrors the changes in native aar_import: bazelbuild/bazel#21225

PiperOrigin-RevId: 621204597
Change-Id: I75f9eb693b30fc0987a376b877fda156990dc6cf
restingbull added a commit to bazelbuild/rules_kotlin that referenced this issue Dec 20, 2024
restingbull added a commit to bazelbuild/rules_kotlin that referenced this issue Dec 20, 2024
restingbull added a commit to bazelbuild/rules_kotlin that referenced this issue Dec 20, 2024
restingbull added a commit to bazelbuild/rules_kotlin that referenced this issue Dec 21, 2024
restingbull added a commit to bazelbuild/rules_kotlin that referenced this issue Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug
Projects
None yet
Development

No branches or pull requests

6 participants