How to import OpenCV android-sdk to my project which is using Bazel?

时间:2019-05-31 11:43:35

标签: android bazel opencv4android

I have been trying to import opencv-android-sdk to my Bazel project but I am not able to do it.

I tried the this answer on SO but while building my project I get errors that

error: package org.opencv.android does not exist

1 个答案:

答案 0 :(得分:1)

我发现Maven中有一个opencv-android artifact

您可以使用rules_jvm_external来依赖它。

在您的WORKSPACE文件中,指定依赖关系以及其他外部依赖关系:

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
    artifacts = [
        "org.opencv:opencv-android:1.0.1",
        # ...
    ],
    repositories = [
        "https://maven.google.com",
        "https://jcenter.bintray.com",
    ],
)

然后,在包含Android目标的BUILD文件中,取决于OpenCV目标:

android_library(
     name = "my_lib",
     custom_package = "com.example.bazel",
     srcs = glob(["java/com/example/bazel/*.java"]),
     manifest = "java/AndroidManifest.xml",
     resource_files = glob(["res/**"]),
     deps = [
         "@maven//:org_opencv_opencv_android",
     ],
     visibility = ["//src/test:__subpackages__"]
)

最后,您应该能够在Android Java代码中引用类似org.opencv.core.Core的类。

P.S。考虑将所有maven_jargmaven_rules / gmaven_artifact切换为使用rules_jvm_external。不赞成使用以前的Maven规则,而推荐使用rules_jvm_external