例如,在我的Android项目中导入模块依赖项。为了使我的应用程序与Flic兼容,我必须将整个Flic项目作为模块依赖项导入到我现有的Android项目中。使用gradle构建时,它工作正常,但使用Bazel,在导入任何类的Flic时显示错误。

最佳答案

我不熟悉Flic,但是看着instructions here,看来flic可以依赖于使用http_archive并为其编写一个小的android_library规则:

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
  name = "flic-android",
  # latest commit as of writing this answer
  url = "https://github.com/50ButtonsEach/fliclib-android/archive/ddfbfebfd5090bb2cc80a7e66c613134ffc4071a.zip",
  build_file = "@//:BUILD.flic-android",
  strip_prefix = "fliclib-android-ddfbfebfd5090bb2cc80a7e66c613134ffc4071a"
)


BUILD.flic-android(将此放在WORKSPACE文件旁边):

package(default_visibility = ["//visibility:public"])

android_library(
  name = "flic",
  manifest = "fliclib/src/main/AndroidManifest.xml",
  srcs = glob(["fliclib/src/main/java/io/flic/lib/*.java"]),

  idl_srcs =        glob(["fliclib/src/main/aidl/io/flic/lib/*.aidl"]),
  # "external/flic-android" must be included in the import root because this
  # rule is being evaluated in an external repository
  idl_import_root = "external/flic-android/fliclib/src/main/aidl",

  custom_package = "io.flic.lib",
)


最后,将"@flic-android//:flic"添加到任何使用Flic的depsandroid_binary规则的android_library中。

(附带说明:flic的build.gradle filecom.android.support:appcompat-v7:22.1.1列为编译时依赖项,但似乎不需要编译库,因此在此未包括)

10-08 14:45