Search code examples
bazel

How to set //external:android/sdk when it is not bound to anything


While trying to build a git repo which uses bazel I got the error that //external:android/sdk was not bound to anything and I cannot find where this configuration is found so I can fix it.

I have loaded up a new ubuntu 14.04 and I'm trying to build github.com/google/shipshape from source. I have followed the instructions given here to install everything I need to build it.

Basically installed golang, openjdk-8-jdk, openjdk-8-source, bazel and the ran the following:

mkdir -p github.com/google && cd github.com/google
git clone https://github.com/google/shipshape.git
cd shipshape
./configure        # Run initial Shipshape+Bazel setup
bazel build //...  # Build all Shipshape source

but when I come to building with bazel build //... I get this error:

____Loading package: shipshape
____Loading package: shipshape/util/rpc/client
____Loading package: shipshape/analyzers/codealert
____Loading package: shipshape/contrib/phabricator
____Loading package: shipshape/javatests/com/google/shipshape/analyzers
____Loading package: third_party/kythe/java/com/google/devtools/kythe/platform/shared
____Loading package: third_party/go-glog
____Loading package: third_party/guava
____Loading package: third_party/gson
____Loading package: shipshape/test/dind/docker
____Loading package: third_party/bazel/tools/jdk
____Loading package: tools/test
____Loading...
____Loading package: @bazel_tools//tools/cpp
____Loading package: @local-jdk//
____Loading package: @bazel_tools//tools/genrule
____Loading package: @bazel_tools//tools/test
____Loading package: @bazel_tools//third_party/java/jdk/langtools
____Loading complete.  Analyzing...
ERROR: /DEFAULT.WORKSPACE:75:1: in bind rule //external:android/sdk: The external label '//external:android/sdk' is not bound to anything.
ERROR: Analysis of target '//tools/defaults:android_jar' failed; build aborted.
____Elapsed time: 3.086s

A Google search gave me this link which states

which doesn't tell you at all that you need to update some information in your WORKSPACE to point to your Android SDK. It would be nice to have a friendlier error message.

I interpret that as there is a binding somewhere which I should update, so an existing line of code that needs to be updated.

But the WORKSPACE in the folder in which I am supposed to just execute build in is empty, so there should be another file which has a bind which I could edit.

I found this folder /home/alex/.bazel/base_workspace but I did not find any WORKSPACE that seem to be the correct one to edit.

I also found these with grep: ~/.cache/bazel/_bazel_root/hash/README ~/.cache/bazel/_bazel_root/hash/external/local-jdk/WORKSPACE But seeing as they are in cache thats probably wrong.

So either DEFAULT.WORKSPACE is somewhere else and I need to do some bind thing there to get it to find my android sdk, or DEFAUL.WORKSPACE really is the empty WORKSPACE inside my shipshape folder which is filled during bazel build runtime and then removed afterwards.

But in either case I am at a loss as to how I should bind //external:android/sdk to anything.


Solution

  • At the moment, building //... doesn't work great because it includes everything Bazel might need to build any language or platform. (This has actually been fixed at HEAD, but is not yet in a release). I'd recommend running bazel build //shipshape/... for now.

    (And if you were building Android targets, you would want to setup your WORKSPACE file as described here, but you're not, so don't bother.)