Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.eightcard:OpenCV-Android:'
}
dependencies {
implementation("com.github.eightcard:OpenCV-Android:")
}
<dependency>
<groupId>com.github.eightcard</groupId>
<artifactId>OpenCV-Android</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.eightcard" % "OpenCV-Android" % ""
:dependencies [[com.github.eightcard/OpenCV-Android ""]]
OpenCV4Android, packaged as a .aar for direct use without depending on the stupid OpenCV Manager app.
Building OpenCV-3.x.y for Android is actually quite simple, its just not obvious where to get the pieces and the OpenCV docs hard-sell the "OpenCV Manager" in favour of the better and easier direct integration approach.
Here's the steps I used to create my .aar:
Reference the maven repository
repositories {
maven { url 'https://github.com/eightcard/opencv-android/raw/master/maven-repo' }
}
Include the .aar in your build.gradle file:
dependencies {
compile 'com.github.eightcard:OpenCV-Android:3.2.0'
}
Bootstrap OpenCV in your Java code:
import org.opencv.android.OpenCVLoader;
...
if (OpenCVLoader.initDebug()) {
// do some opencv stuff
}
Optional but recommended: to keep the downloaded APK size to a minimum, build separate APK's per architecture (approx 10MB each vs 42MB for universal) by placing the following inside the 'android' gradle directive of your application's build.gradle:
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
universalApk false
}
}
Disclaimer: This project is simply my bundling of OpenCV as an Android Library. I am not otherwise involved in the OpenCV project, and all credit for the wonderful OpenCV library goes to the developers thereof.