bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Bazel tries to use dx instead of d8 if using default dex_shards with Android Build Tools >=31

Open pswaminathan opened this issue 2 years ago • 3 comments

Description of the bug:

Android build tools >=31 removed dx in favor of d8. However, when building an android_binary, Bazel still attempts to use dx if dex_shards is 1 (as the unset default or explicitly set to 1). Setting a non-standard dex_shards makes this go away, but Bazel shouldn't be trying to use dx regardless.

This behavior persists even if using flags to explicitly use d8:

build --define=android_dexmerger_tool=d8_dexmerger
build --define=android_incremental_dexing_tool=d8_dexbuilder
build --define=android_standalone_dexing_tool=d8_compat_dx

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

Example project at https://github.com/pswaminathan/barest-kotlin/pull/2.

58e6843 updates the build tools to a version without dx. This commit does not build. The error message I receive is:

ERROR: /private/var/tmp/_bazel_p/afc4c6dd0737eebec931aeb282f26bc9/external/androidsdk/BUILD.bazel:13:25: Extracting interface @androidsdk//:dx_jar_import [for tool] failed: missing input file '@androidsdk//:build-tools/31.0.0/lib/dx.jar'

56e4806 fixes it simply by adding dex_shards = 2.

Which operating system are you running Bazel on?

macOS Monterey (12.5.1)

What is the output of bazel info release?

release 6.0.0-pre.20220818.1

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 master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

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

No response

pswaminathan avatar Aug 27 '22 13:08 pswaminathan

Hello @pswaminathan, Could you please share the right URL links for the given links https://github.com/pswaminathan/barest-kotlin/pull/2, 58e6843, 56e4806. These pages are not available. Thanks!

sgowroji avatar Aug 29 '22 04:08 sgowroji

@sgowroji whoops, I made the repository private by accident. I've made it public now so those links should work!

pswaminathan avatar Aug 29 '22 21:08 pswaminathan

Hmm, I wasn't able to reproduce this:

barest-kotlin$ cat android/app/BUILD.bazel 
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")

kt_android_library(
    name = "lib",
    srcs = ["MainActivity.kt"],
    visibility = ["//visibility:private"],
    deps = [
    ],
)

android_binary(
    name = "app",
    deps = [":lib"],
    manifest = "AndroidManifest.xml",
    dex_shards = 1,
)

barest-kotlin$ ls ~/android-sdk/build-tools/
33.0.0

barest-kotlin$ bazel version
Starting local Bazel server and connecting to it...
Build label: 6.0.0-pre.20220818.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Aug 24 17:12:26 2022 (1661361146)
Build timestamp: 1661361146
Build timestamp as int: 1661361146

barest-kotlin$ bazel clean --expunge
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.

barest-kotlin$ bazel build android/app
Starting local Bazel server and connecting to it...
INFO: Analyzed target //android/app:app (64 packages loaded, 1107 targets configured).
INFO: Found 1 target...
Target //android/app:app up-to-date:
  bazel-bin/android/app/app_deploy.jar
  bazel-bin/android/app/app_unsigned.apk
  bazel-bin/android/app/app.apk
INFO: Elapsed time: 23.307s, Critical Path: 10.05s
INFO: 71 processes: 35 internal, 24 linux-sandbox, 12 worker.
INFO: Build completed successfully, 71 total actions

@pswaminathan could you confirm that this still fails? or perhaps I missed something in the repro?

ahumesky avatar Sep 16 '22 00:09 ahumesky

Hello @pswaminathan, Could you please check the above comment and reply. Thanks

sgowroji avatar Sep 26 '22 09:09 sgowroji

Hmm, interesting, I'm not able to reproduce it now either. Maybe something was cached? Interestingly, one of our other team members was experiencing this as well. I'll ask him to try reproducing again.

pswaminathan avatar Sep 29 '22 15:09 pswaminathan

Thank you for the reply. We will be waiting to hear it from you.

sgowroji avatar Oct 12 '22 12:10 sgowroji

let us know if this is still an issue

ahumesky avatar Oct 25 '22 20:10 ahumesky