Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaCV configuration in Android Studio

Tags:

android

javacv

I know there is a lot of similiar questions to this, but a lot of them seem to be out of date because of the development of libraries such JavaCV.

I used the code from Video Creation with Images and Audio in Android to create movie, but I have a problem with lib imports.

I did as JavaCV page says, I put dependency in gradle :

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

now, I don't know if I have to do something else?

I have used these imports :

import org.bytedeco.javacpp.avcodec;
import org.bytedeco.javacpp.opencv_core.IplImage;
import org.bytedeco.javacv.FFmpegFrameRecorder;

import static org.bytedeco.javacpp.opencv_highgui.cvLoadImage;

and get this error :

Caused by: java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.javacpp.avutil
        at org.bytedeco.javacpp.Loader.load(Loader.java:387)
        at org.bytedeco.javacpp.Loader.load(Loader.java:353)
        at org.bytedeco.javacpp.avformat.<clinit>(avformat.java:13)
        at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:106)
        at voidstudio.app.activity.CreateMovieTask.doInBackground(CreateMovieTask.java:46)
        at voidstudio.app.activity.CreateMovieTask.doInBackground(CreateMovieTask.java:21)

and

Caused by: java.lang.ClassNotFoundException: org.bytedeco.javacpp.avutil
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:217)

and

 Caused by: java.lang.UnsatisfiedLinkError: Couldn't load jniavutil from loader dalvik.system.PathClassLoader[dexPath=/data/app/voidstudio.app-1.apk,libraryPath=/data/app-lib/voidstudio.app-1]: findLibrary returned null
        at java.lang.Runtime.loadLibrary(Runtime.java:365)
        at java.lang.System.loadLibrary(System.java:521)
        at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535)
        at org.bytedeco.javacpp.Loader.load(Loader.java:410)

did I missed sth in configuration? I have seen similiar questions but there was no proper answer for this.

like image 230
filipp.kowalski Avatar asked Sep 04 '14 08:09

filipp.kowalski


2 Answers

Check the placement of jniLibs folder

I have just changed the placement of my jniLibs (before it was outside main folder) and this worked for me, please check the image! hope this will help

like image 43
Yourange Avatar answered Sep 28 '22 08:09

Yourange


Update! I've also found out that if you have have an armeabi-v7a folder in the jniLibs, or are using anything other than an armeabi folder, you will have issues with the .so files not being added.

Looks like ffmpeg is not being imported. I had the same problem. Here is what I did. Let me know if this helps you!

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'
like image 61
tylerjroach Avatar answered Sep 28 '22 08:09

tylerjroach