使用JavaCV Android Studio的问题

时间:2016-07-09 03:03:49

标签: android opencv javacv

所以我正在尝试将JavaCV与Android Studio一起使用。我正在尝试使用FaceRecognizer类的包装器。我试过让这段代码运行几个小时但到目前为止没有运气。我不断收到构建错误:

     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'

我解压缩了opencv的.so文件并拆分成两个文件:armeabi和x86,所以没关系。

这是我的build.gradle文件:

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'

    }

我不知道如何从这里开始。我需要对build.gradle进行哪些修改才能进行编译?我尝试使用javacv 1.1但是我在运行时遇到错误,而.so文件都来自javacv 1.2。

1 个答案:

答案 0 :(得分:1)

我有类似的问题。 Gradle的依赖解析显然存在一个错误。 Javacpp的作者已经提供了一种解决方法,请参见此处:https://github.com/bytedeco/javacv/issues/432

尝试在build.gradle脚本中包含以下代码:

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

它对我有用,希望能帮到你。