Skip to content

Commit

Permalink
Improve error message when building Android rules without an SDK.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#509.

Example output:

```
$ bazel build //:all
INFO: Found 1 target...
ERROR: /usr/local/google/home/ajmichael/.cache/bazel/_bazel_ajmichael/7fcc7480abc634522e5c0cfe6b85b583/external/bazel_tools/tools/android/BUILD:236:1: Executing genrule @bazel_tools//tools/android:no_android_sdk_repository_error failed: Process exited with status 1 [sandboxed].
This build requires an Android SDK. Please add the android_sdk_repository rule to your WORKSPACE.
Use --strategy=Genrule=standalone to disable sandboxing for the failing actions.
Target //:lib failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.327s, Critical Path: 0.10s
```

RELNOTES: Attempting to build an Android target without setting up android_sdk_repository will now produce a helpful error message.
PiperOrigin-RevId: 155158667
  • Loading branch information
aj-michael authored and damienmg committed May 5, 2017
1 parent 14747a8 commit 71ed1ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bind(name = "android/sdk")
bind(name = "android/sdk", actual = "@bazel_tools//tools/android:poison_pill_android_sdk")
bind(name = "android/dx_jar_import", actual = "@bazel_tools//tools/android:no_android_sdk_repository_error")
bind(name = "android/crosstool", actual = "@bazel_tools//tools/cpp:toolchain")
bind(name = "android_sdk_for_testing", actual = "//:dummy")
bind(name = "android_ndk_for_testing", actual = "//:dummy")
31 changes: 31 additions & 0 deletions tools/android/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,34 @@ alias(
name = "databinding_annotation_processor",
actual = "@android_databinding//:annotation_processor",
)

# This is the default binding of //external:android/sdk. If someone attempts to
# build a rule that depends on //external:android/sdk without setting up
# android_sdk_repository in their WORKSPACE, the genrule will fail with a
# helpful error message.
android_sdk(
name = "poison_pill_android_sdk",
proguard = ":error_message",
aapt = ":error_message",
dx = ":error_message",
main_dex_list_creator = ":error_message",
adb = ":error_message",
framework_aidl = ":error_message",
aidl = ":error_message",
android_jar = ":error_message.jar",
shrinked_android_jar = ":error_message.jar",
annotations_jar = ":error_message.jar",
main_dex_classes = ":error_message",
apksigner = ":error_message",
zipalign = ":error_message",
resource_extractor = "error_message",
)

genrule(
name = "no_android_sdk_repository_error",
outs = ["error_message", "error_message.jar"],
cmd = """echo \
This build requires an Android SDK. Please add the android_sdk_repository \
rule to your WORKSPACE. ; \
exit 1 """,
)

0 comments on commit 71ed1ee

Please sign in to comment.