JavaCV + Android Studio + gradle- possible?

前端 未结 7 1273
难免孤独
难免孤独 2021-01-31 21:19

I\'m trying use JavaCV with Android Studio and Gradle. I wrote such code fragment:

   repositories {
    mavenCentral()
    maven {
        url \"http://maven2.j         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 21:47

    EDIT. Solution in this post is deprecated and may contain some errors. Please see recent, correct post at the bottom of the page.

    Ok, I did it on my own :). So here is what we should do to use JavaCV in Android Studio:

    1) First we should add such dependencies to build.gradle inside project:

    dependencies {
        compile group: 'com.googlecode.javacpp', name: 'javacpp', version: '0.7'
        compile group: 'com.googlecode.javacv', name: 'javacv', version: '0.7'}
    

    (I mean: build.gradle inside our module directory)

    Thanks that we get javacv.jar and javacpp.jar inside external libraries (if not, we should restart Android Studio).

    2) If we follow the Eclipse instruction on javacv official site we are now in point 4.:

    Extract all the *.so files rom javacv-android-arm.jar, opencv-2.4.8-android-arm.jar, and ffmpeg-2.1.1-android-arm.jar directly into the newly created "libs/armeabi" folder, without creating any of the subdirectories found in the JAR files.

    We have to extract all *.so files which we need, but then we should join them to our project in other special way: 3rd answer here says about it, but generally, we should:

    1. Create new 'armeabi' directory
    2. Put interesting .so files into 'armeabi' directory
    3. Create armeabi.zip
    4. Change extension of armeabi.zip to armeabi.jar
    5. Put armeabi.jar to 'libs' directory
    6. Make sure that build.gradle of our module contains such dependency:
      compile fileTree(dir: 'libs', include: ['*.jar'])

    3) Enjoy your OpenCV and JavaCv in Android Studio (and don't forget to add

    
    
    

    to your AndroidManifest.xml if you want to read/save image from/to sdcard and try thanks this, that your project works well).

    /////////////////////////////////////////////////////////
    If something is wrong, please write about it in comments.

提交回复
热议问题