如何在使用Bazel作为构建系统的Android项目中导入外部模块/依赖项(例如Flic)?

时间:2019-05-27 12:09:22

标签: java android bazel

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

1 个答案:

答案 0 :(得分:1)

我不熟悉Flic,但是看着instructions here,看来flic可以依赖使用config.consider_all_requests_local = true并为其编写一条小的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的"@flic-android//:flic"deps规则的android_binary中。

(附带说明:flic的build.gradle fileandroid_library列为编译时依赖项,但似乎不需要编译库,因此这里未包括在内)< / p>