georgetheevilman
georgetheevilman

Reputation: 177

Issue with using JavaCV Android Studio

So I am trying to use JavaCV with Android Studio. I am trying to use the wrapper for the FaceRecognizer class. I have tried getting this code running for hours but no luck so far. I keep getting a build error:

     Error:A problem occurred configuring project ':app'.
     > Could not find javacpp-presets-Mac OS X-x86_64.jar
      (org.bytedeco:javacpp-presets:1.2).
      Searched in the following locations:
      https://jcenter.bintray.com/org/bytedeco/javacpppresets/1.2/javacpp-presets-1.2-Mac OS X-x86_64.jar'

I unzipped the .so files for opencv and split into two files: armeabi and x86, so thats fine.

Here is my build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    sourceSets.main.jni.srcDirs = []

    //task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
    //    ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
    //    //on Windows, you need to add ".cmd" after "ndk-build" below
    //    commandLine "$ndkDir/ndk-build",
    //            'NDK_PROJECT_PATH=build/intermediates/ndk',
    //            'NDK_LIBS_OUT=src/main/jniLibs',
    //            'APP_BUILD_SCRIPT=src/main/jniLibs/Android.mk',
    //            'NDK_APPLICATION_MK=src/main/jniLibs/Application.mk'
    //}
    //task ndkLibsToJar(type: Zip, dependsOn: 'ndkBuild', description: 'Create a JAR of the native libs') {
    //    destinationDir new File(buildDir, 'libs')
    //    baseName 'ndk-libs'
    //    extension 'jar'
    //    from(new File(buildDir, 'libs')) { include '**/*.so' }
    //    into 'lib/'
    //}
    //tasks.withType(JavaCompile) {
    //    compileTask -> compileTask.dependsOn ndkBuild
    //}
    defaultConfig {
        applicationId "com.example.manavdutta1.affdexdemo"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        //exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
        //exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'

        //might need these if you use openCV
        exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
        exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
        testCompile 'junit:junit:4.12'
        compile project(path: ':openCVLibrary2411')
        compile files('src/main/libs/faceapi.jar')
        compile files('src/main/libs/faceppsdk.jar')
        //compile files('src/main/libs/artoolkitplus.jar')
        //compile files('src/main/libs/ffmpeg.jar')
        //compile files('src/main/libs/flandmark.jar')
        //compile files('src/main/libs/flycapture.jar')
        //compile files('src/main/libs/javacpp.jar')
        //compile files('src/main/libs/javacv.jar')
        //compile files('src/main/libs/arm/opencv-android-arm.jar')
        //compile files('src/main/libs/x86/opencv-android-x86.jar')
        //compile files('src/main/libs/libdc1394.jar')
        //compile files('src/main/libs/libfreenect.jar')
        //compile files('src/main/libs/opencv.jar')
        //compile files('src/main/libs/videoinput.jar')
        compile 'com.android.support:appcompat-v7:23.3.0'
        compile 'com.affectiva.android:affdexsdk:3.0.1'
        compile 'com.microsoft.projectoxford:face:1.0.0'
        compile 'com.microsoft.projectoxford:emotion:1.0.0'
        compile 'com.android.support:design:23.3.0'
        compile 'org.bytedeco:javacv:1.2'
        compile 'org.bytedeco.javacpp-presets:opencv:3.0.0-1.1:android-x86'
        compile 'org.bytedeco.javacpp-presets:opencv:3.0.0-1.1:android-arm'
        //compile group: 'org.bytedeco', name: 'javacv', version: '1.2'

        //compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.10-0.10', classifier: 'android-arm'
        //compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.5.1-0.10', classifier: 'android-arm'

    }

Im not sure how to proceed from here. What modifications do I need to make to build.gradle to get this compiling? I tried using javacv 1.1 but I got an error at runtime, and the .so files all come from javacv 1.2.

Upvotes: 0

Views: 1164

Answers (1)

Max Pole
Max Pole

Reputation: 319

I had a similar problem. There is apparently a bug in Gradle's dependency resolution. The author of Javacpp has already provided a workaround, see here: https://github.com/bytedeco/javacv/issues/432

Try to include the following code in your build.gradle script:

configurations {
    all*.exclude group: 'org.bytedeco', module: 'javacpp-presets'
}

It works for me and will hopefully do for you.

Upvotes: 1

Related Questions