How to Set up JavaCV for Android Studio?

569 Views Asked by At

I am trying to implement these techniques and algorithms: Image Filtering, Edge Detection, Image Binarization, Contour Detection, Cell Segmentation using JavaCV

But I don't know how to set up JavaCV for specifically for android but at GitHub of JavaCV documentation provide this Gradle:

     dependencies {
            implementation group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.8'
         }

Which include all jar file for different platform but in this case only jar file for android is required.

I downloaded the javacv-platform-1.5.8-bin.zip file and try to copy the jar file to libs folder in Android studio project but there is no file name javacv-android-arm.jar in javacv-platform-1.5.8-bin.zip.

So if someone can help me locate which jar file is required and how i can add then correctly or how to set up Android Studio Project for javaCV

Thanks.

**Version: **Android Studio Electric Eel | 2022.1.1 Patch 2 Android Gradle Plugin Version: 7.3.1 Gradle Version: 7.4

I tired adding different jar file but few of the function and method are not able to import into the project Error: Rename Reference

1

There are 1 best solutions below

0
spring_chicken On

adding this bit to the app's build.gradle seems to do the trick:

configurations {
    javacpp
}

task javacppExtract(type: Copy) {
    dependsOn configurations.javacpp

    from { configurations.javacpp.collect { zipTree(it) } }
    include "lib/**"
    into "$buildDir/javacpp/"
    android.sourceSets.main.jniLibs.srcDirs += ["$buildDir/javacpp/lib/"]

    tasks.getByName('preBuild').dependsOn javacppExtract
}

dependencies {

    ... original ...

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation group: 'org.bytedeco', name: 'javacv', version: '1.5.9'
    javacpp group: 'org.bytedeco', name: 'openblas-platform', version: '0.3.23-1.5.9'
    javacpp group: 'org.bytedeco', name: 'opencv-platform', version: '4.7.0-1.5.9'
    javacpp group: 'org.bytedeco', name: 'ffmpeg-platform', version: '6.0-1.5.9'
}