0

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

Community
  • 1
  • 1
sonudelhikkc
  • 134
  • 10
  • Can you please share what your BUILD and WORKSPACE files look like? – Jin Jun 02 '19 at 23:56
  • This is what my [WORKSPACE](https://pastebin.com/VwjBgEQk), [opencv.BUILD](https://pastebin.com/Gbay5YST) and [app/BUILD](https://pastebin.com/25TpxJi7). But what I think is that the [SO answer](https://stackoverflow.com/questions/34984290/building-opencv-code-using-bazel/35024014#35024014) I referred to was for C++ project not for android project. – sonudelhikkc Jun 03 '19 at 04:59

1 Answers1

1

I see that there's an opencv-android artifact on Maven.

You can depend on this using rules_jvm_external.

In your WORKSPACE file, specify the dependency along with the other external dependencies:

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",
    ],
)

Then, in your BUILD file containing your Android targets, depend on the OpenCV target:

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__"]
)

Finally, you should be able to reference classes like org.opencv.core.Core in your Android Java code.

P.S. consider switching all your maven_jar and gmaven_rules/gmaven_artifact to use rules_jvm_external. The former Maven rules have been deprecated in favor of rules_jvm_external.

Jin
  • 12,748
  • 3
  • 36
  • 41