JavaCV + Android Studio + gradle- possible?

前端 未结 7 1094
难免孤独
难免孤独 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

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    

    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.

    0 讨论(0)
  • 2021-01-31 21:47

    If you try out with javacv 1.2, we have to do some additional steps so at to get this working. Here is my build.gradle file

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"
    
        defaultConfig {
            applicationId "org.audiorecording"
            minSdkVersion 15
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        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'
        }
    }
    
    repositories {
        mavenCentral()
    }
    
    configurations {
        all*.exclude group: 'org.bytedeco', module: 'javacpp-presets'
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.1'
        compile 'com.android.support:design:24.2.1'
        compile 'org.bytedeco:javacv:1.2'
        compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.1.0-1.2', classifier: 'android-arm'
        compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.0.2-1.2', classifier: 'android-arm'
    
    }
    
    0 讨论(0)
  • 2021-01-31 21:49

    Unfortunately, I had some problems with user2645214's solution (still getting java.lang.UnsatisfiedLinkError), but I found another one, so I decided to share it with those who would have the same problem.

    Since release 0.7.3 there is another way to include your *.so files - you can just put them in /src/main/jniLibs (just create jniLibs directory if you don't have it) and it should work.

    Also my build.gradle file looks like:

    apply plugin: 'android'
    
    repositories {
        mavenCentral()
        maven { url 'http://maven2.javacv.googlecode.com/git/' }
    }
    
    dependencies {
        compile 'com.android.support:appcompat-v7:20.+'
        compile 'com.googlecode.javacpp:javacpp:0.7'
        compile 'com.googlecode.javacv:javacv:0.7'
    }
    
    android {
        compileSdkVersion 20
        buildToolsVersion '20.0.0'
    
        defaultConfig {
            applicationId "com.example.agp.testapplication2"
            minSdkVersion 15
            targetSdkVersion 20
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-31 21:49

    I faced this issue on Windows 7 x64. Here is a section from my gradle.build file which resolved the problem:

    compile("org.bytedeco:javacv:0.11")
    compile("org.bytedeco.javacpp-presets:opencv:2.4.11-0.11:windows-x86_64")
    compile("org.bytedeco.javacpp-presets:ffmpeg:2.6.1-0.11:windows-x86_64")
    
    0 讨论(0)
  • 2021-01-31 21:53

    1.WARNING: That's not enough!:

      dependencies { compile group: 'org.bytedeco', name: 'javacv', version: '0.9'}
    

    2.EDIT: Sorry for mistake, my recent solution which I posted here and which told only about line above was wrong. But I checked it out and this works for me:

    a)Add dependencies

    dependencies {
        compile group: 'org.bytedeco', name: 'javacv', version: '0.9'
        compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.9-0.9', classifier:    'android-arm'
        compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.3-0.9', classifier: 'android-arm'    
    }
    

    b) Create jniLibs dir inside your project (on the same level as normal libs dir. EDIT: If you have some troubles try moving jniLibs to app/src/main).
    c) Add required .so files extracted from opencv-android-arm.jar and ffmpeg-android-arm.jar (or only this files which you really need) to created jniLibs dir. (If you don't know about what I'm talking you can download javacv-0.9-bin.zip from JavaCV page and inside it you can find these 2 .jars).

    0 讨论(0)
  • 2021-01-31 22:01

    Inserting inside the build.gradle dependencies worked for me:

    compile ‘org.bytedeco:javacv:+’
    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’
    
    0 讨论(0)
提交回复
热议问题