Mkr Mkr - 6 months ago 222
Android Question

JavaCV + Android Studio + gradle- possible?

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

repositories {
mavenCentral()
maven {
url "http://maven2.javacv.googlecode.com/git/"
}
}

dependencies {
compile files('libs/android-support-v4.jar')
compile group: 'com.googlecode.javacpp', name: 'javacpp', version: '0.5'
compile group: 'com.googlecode.javacv', name: 'javacv', version: '0.5'
}


and I see imported libraries in dir External Libraries. So I tried to run this:

...
IplImage zdjecie=cvLoadImage(Environment.getExternalStorageDirectory().getPath()+ "/1.bmp");
cvSaveImage(Environment.getExternalStorageDirectory().getPath()
+ "/2.bmp", zdjecie);
...


and I got error:

Caused by: java.lang.UnsatisfiedLinkError: Couldn't load jniopencv_core: findLibrary returned null


...because I don't know what should I do with opencv's (and others) .so files.

So how should we use JavaCV in Android Studio?

Mkr Mkr
Answer

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).