rules_android icon indicating copy to clipboard operation
rules_android copied to clipboard

@@androidsdk//:dx_jar_import' is misplaced

Open kiritgothi opened this issue 1 year ago • 11 comments

Description of the bug:

/bazel_tools/tools/android/BUILD:248:12: in runtime_deps attribute of java_binary rule @@bazel_tools//tools/android:dexer: alias '//external:android/dx_jar_import' referring to filegroup rule '@@androidsdk//:dx_jar_import' is misplaced here (expected cc_binary, cc_library, genrule, genproto, java_import, java_library, java_proto_library, java_lite_proto_library, proto_library, sh_binary or sh_library) and '@@androidsdk//:dx_jar_import' does not have mandatory providers: 'CcInfo' or 'JavaInfo'. Since this rule was created by the macro 'java_binary', the error might have been caused by the macro implementation

Which category does this issue belong to?

No response

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

No response

Which operating system are you running Bazel on?

Windows 11, And Ubuntu 22.0

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 ?

No response

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

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

kiritgothi avatar Mar 07 '24 18:03 kiritgothi

@kiritgothi Could you please provide complete steps to reproduce this issue? Thanks

iancha1992 avatar Mar 07 '24 21:03 iancha1992

I am building "android-testdpc" project with "bazel build testdpc" command. Unfortunately I got error in both windows and ubuntu. This error comes from cache file of bazel which build.

ERROR: %user%/jjzqyj3b/external/bazel_tools/tools/android/BUILD:248:12: in runtime_deps attribute of java_binary rule @@bazel_tools//tools/android:dexer: alias '//external:android/dx_jar_import' referring to filegroup rule '@@androidsdk//:dx_jar_import' is misplaced here (expected cc_binary, cc_library, genrule, genproto, java_import, java_library, java_proto_library, java_lite_proto_library, proto_library, sh_binary or sh_library) and '@@androidsdk//:dx_jar_import' does not have mandatory providers: 'CcInfo' or 'JavaInfo'. Since this rule was created by the macro 'java_binary', the error might have been caused by the macro implementation ERROR: %user%/jjzqyj3b/external/bazel_tools/tools/android/BUILD:248:12: Analysis of target '@@bazel_tools//tools/android:dexer' failed ERROR: Analysis of target '//:testdpc' failed; build aborted: Analysis failed INFO: Elapsed time: 15.281s, Critical Path: 0.07s INFO: 1 process: 1 internal. ERROR: Build did NOT complete successfully

kiritgothi avatar Mar 08 '24 03:03 kiritgothi

Are you using the rules from github.com/bazelbuild/rules-android or the built-in ("native") android rules? Do you see the same failure if you pass --enable_bzlmod=false?

ahumesky avatar Mar 12 '24 19:03 ahumesky

Answering my own question, looking at https://github.com/googlesamples/android-testdpc/blob/master/BUILD, these are the native rules.

ahumesky avatar Mar 12 '24 20:03 ahumesky

I wasn't able to reproduce this error, here or during debugging in https://github.com/bazelbuild/bazel/issues/21632 with a fork of android-testdpc (at the time it had only 1 commit difference that shouldn't be relevant here) -- are there any other details you can give to help reproduce the error?

ahumesky avatar Mar 13 '24 01:03 ahumesky

I did some tests as well on two different machines (Mac OS and Debian) and I cannot reproduce this with Bazel v7.1.0.

pfmaggi avatar Mar 13 '24 10:03 pfmaggi

I think this may be happening with bzlmod projects when the $ANDROID_HOME environment variable is not set

gottagofaster236 avatar Mar 22 '24 14:03 gottagofaster236

I faced that issue but resolved with

I think this may be happening with bzlmod projects when the $ANDROID_HOME environment variable is not set

above gottagofaster236's comment.

export ANDROID_HOME={YOUR_HOME_DIR}/Android/Sdk

seokil628 avatar Mar 30 '24 16:03 seokil628

I'm experiencing the same issue for the first time while building this new Bazel build for testDPC 9.0.6. I've tried export ANDROID_HOME={YOUR_HOME_DIR}/Android/Sdk and type env command on the terminal if the environment variable is set, but the issue still persist.

I'm using Bazel v7.1.1 and Debian OS. I will get back if ever I find a fix for this.

rey-aquino avatar Apr 03 '24 23:04 rey-aquino

I'm experiencing the same issue for the first time while building this new Bazel build for testDPC 9.0.6. I've tried export ANDROID_HOME={YOUR_HOME_DIR}/Android/Sdk and type env command on the terminal if the environment variable is set, but the issue still persist.

I'm using Bazel v7.1.1 and Debian OS. I will get back if ever I find a fix for this.

I tried this one again and it works. Make sure that you run export ANDROID_HOME={YOUR_HOME_DIR}/Android/Sdk inside android-testdpc folder, after that run bazel build testdpc

rey-aquino avatar Apr 05 '24 11:04 rey-aquino

android_sdk_repository still references dx: https://github.com/bazelbuild/rules_android/blob/8ab67ca94822a78ad9acca87734beab3d5f69411/rules/android_sdk_repository/helper.bzl#L398-L411 that should just be removed

ahumesky avatar Dec 13 '24 19:12 ahumesky