Search code examples
androidandroid-support-librarybazel

Using appcompat-v7 in a bazel build


I'm trying to get started with Bazel for compiling for Android, and I'm having some problems with my app UI - specifically, if I try to have a UI, Bazel chokes.

The main activity looks like this:

package org.mamizou.example.test
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
....
public class MainActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
    }
}

So according to android.developer.com, the right thing to do if I want to use appcompat-v7 is just in my android_library block, include "//external:android/appcompat_v7". Cool. My android_library block now looks like this:

android_library(
    name="lib",
    deps=[ "//external:android/appcompat_v7", ],
    srcs=[ "src/org/mamizou/example/test/ExampleLib.java", ],
)

Ok. Then I run bazel build, and I get

ERROR: missing input file '@android_sdk//:extras/android/support/v7/appcompat/libs/android-support-v7-appcompat.jar"

If I go to my android-sdk directory to check it out, I notice that there's a path like android-sdk/extras/android/m2repository/com/android/support/appcompat-v7 but there's no path like android-sdk/extras/android/support

Using the SDK manager tool, I managed to flush my support repository and re-install it, but no change - my support files are all under m2repository. And they're *.aar files, not *.jar files. I can't find anything with a name like *appcompat.jar

So, something's wrong here. It smells like I've done something wrong with my environment configuration, but you've seen the relevant block of BUILD, and my WORKSPACE looks like this:

android_sdk_repository(
    name="android_sdk",
    path="/home/mamizou/android-sdk",
    api_level=23,
    build_tools_version="23.0.2",
)

which looks well-formed to me, at least (and more importantly, points to a real place where the sdk is installed)

  1. Why is Bazel looking for a *.jar in support, when it seems to me that Google's SDK indicates it should be looking for an *.aar under m2repository?
  2. What changes do I need to make so Bazel can find the relevant appcompat-v7 files?

fwiw, Bazel build label is 0.2.0-jdk7


Solution

  • The aar files are coming from "Android Support Repository" under Extras in the SDK manager. For the jars that bazel is using, you'll want to download "Android Support Library". Sorry for the confusion!