JavaCV 0.9 integration to Android Studio

1,596 views
Skip to first unread message

Олег Осипенко

unread,
Aug 1, 2014, 9:07:03 AM8/1/14
to jav...@googlegroups.com
Hi, Samuel!
I am trying to use JavaCV to create video from set of images in my application. I use this code for getting it:

private ArrayList<String> mSelectedImages;
ArrayList<opencv_core.IplImage> images = new ArrayList<>();
for (String path : mSelectedImages) {
    opencv_core
.IplImage img = cvLoadImage(path);
    images
.add(img);
}
FFmpegFrameRecorder frameRecorder = new FFmpegFrameRecorder(outputFilePath, 640, 640, 0);
try {
    frameRecorder
.setVideoCodec(13);
    frameRecorder
.setFrameRate(30);
    frameRecorder
.setPixelFormat(avutil.AV_PIX_FMT_YUV420P); frameRecorder.start();
   
for (int i = 0; i < numOfSlides; i++) {
       
for (int j = 0; j < numOfFramesPerSlide; j++) {
            frameRecorder
.record(images.get(i));
       
}
   
}
    frameRecorder
.stop();
} catch (Exception e) {
    e
.printStackTrace();
}

Unfortunately I can't get desired video, instead of it I'm getting error:

java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.javacpp.opencv_core
            at org
.bytedeco.javacpp.Loader.load(Loader.java:387)
            at org
.bytedeco.javacpp.Loader.load(Loader.java:353)
            at org
.bytedeco.javacpp.opencv_highgui.<clinit>(opencv_highgui.java:13)
            at oleg
.osipenko.agoo.utilities.CodeVideoService.onHandleIntent(CodeVideoService.java:71)
            at android
.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android
.os.Handler.dispatchMessage(Handler.java:107)
            at android
.os.Looper.loop(Looper.java:194)
            at android
.os.HandlerThread.run(HandlerThread.java:60)
     
Caused by: java.lang.ClassNotFoundException: org.bytedeco.javacpp.opencv_core
            at java
.lang.Class.classForName(Native Method)
            at java
.lang.Class.forName(Class.java:217)
            at org
.bytedeco.javacpp.Loader.load(Loader.java:385)
            at org
.bytedeco.javacpp.Loader.load(Loader.java:353)
            at org
.bytedeco.javacpp.opencv_highgui.<clinit>(opencv_highgui.java:13)
            at oleg
.osipenko.agoo.utilities.CodeVideoService.onHandleIntent(CodeVideoService.java:71)
            at android
.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android
.os.Handler.dispatchMessage(Handler.java:107)
            at android
.os.Looper.loop(Looper.java:194)
            at android
.os.HandlerThread.run(HandlerThread.java:60)
     
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load jniopencv_core from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/oleg.osipenko.agoo-1.apk"],nativeLibraryDirectories=[/data/app-lib/oleg.osipenko.agoo-1, /vendor/lib, /system/lib]]]: findLibrary returned null
            at java.lang.Runtime.loadLibrary(Runtime.java:366)
            at java.lang.System.loadLibrary(System.java:514)
            at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535)
            at org.bytedeco.javacpp.Loader.load(Loader.java:410)
            at org.bytedeco.javacpp.Loader.load(Loader.java:353)
            at org.bytedeco.javacpp.opencv_core.<clinit>(opencv_core.java:10)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:217)
            at org.bytedeco.javacpp.Loader.load(Loader.java:385)
            at org.bytedeco.javacpp.Loader.load(Loader.java:353)
            at org.bytedeco.javacpp.opencv_highgui.<clinit>(opencv_highgui.java:13)
            at oleg.osipenko.agoo.utilities.CodeVideoService.onHandleIntent(CodeVideoService.java:71)
            at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.os.HandlerThread.run(HandlerThread.java:60)
     Caused by: java.lang.UnsatisfiedLinkError: Couldn'
t load opencv_core from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/oleg.osipenko.agoo-1.apk"],nativeLibraryDirectories=[/data/app-lib/oleg.osipenko.agoo-1, /vendor/lib, /system/lib]]]: findLibrary returned null
            at java
.lang.Runtime.loadLibrary(Runtime.java:366)
            at java
.lang.System.loadLibrary(System.java:514)
            at org
.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535)
            at org
.bytedeco.javacpp.Loader.load(Loader.java:401)
            at org
.bytedeco.javacpp.Loader.load(Loader.java:353)
            at org
.bytedeco.javacpp.opencv_core.<clinit>(opencv_core.java:10)
            at java
.lang.Class.classForName(Native Method)
            at java
.lang.Class.forName(Class.java:217)
            at org
.bytedeco.javacpp.Loader.load(Loader.java:385)
            at org
.bytedeco.javacpp.Loader.load(Loader.java:353)
            at org
.bytedeco.javacpp.opencv_highgui.<clinit>(opencv_highgui.java:13)
            at oleg
.osipenko.agoo.utilities.CodeVideoService.onHandleIntent(CodeVideoService.java:71)
            at android
.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android
.os.Handler.dispatchMessage(Handler.java:107)
            at android
.os.Looper.loop(Looper.java:194)
            at android
.os.HandlerThread.run(HandlerThread.java:60)

I followed instructions on your github page and did all the tricks I've managed to find, but result stays the same.
This is the part of my build script:
dependencies {
    compile
'com.android.support:appcompat-v7:20.+'
    compile
'com.android.support:support-v4:20.+'
    compile
'com.squareup.picasso:picasso:2.3.2'
    compile project
(':Aviary-SDK')
    compile project
(':dynamicgrid')
    compile files
('libs/ffmpeg.jar')
    compile files
('libs/javacpp.jar')
    compile files
('libs/javacv.jar')
    compile files
('libs/opencv.jar')
    compile files
('libs/armeabi.jar')
    compile files
('libs/ffmpeg-android-arm.jar')
    compile files
('libs/opencv-android-arm.jar')
}

armebi.jar - is a jar archive I made from *.so files I extracted from ffmpeg-android-arm.jar and opencv-android-arm.jar. I also tried to extract it to libs/armeabi directory and include it to my build script using command
compile fileTree('libs/armeabi')
But I still have the same error. Any ideas on how can I get working project?

Alexander Ignatov

unread,
Aug 1, 2014, 9:46:13 AM8/1/14
to jav...@googlegroups.com
Hi. I have got the same message at Eclipse. After spending all day trying to get what was wrong, I downloaded javacv-0.8 and it worked. One thing is critical - make sure you are following instructions from readme.

            at java
.lang.System.loadLibrary(<span s
...

Олег Осипенко

unread,
Aug 1, 2014, 10:12:01 AM8/1/14
to jav...@googlegroups.com
Did you mean these steps from Readme.md?
  1. Go to File > New > Folder, select your project as parent folder, type "libs/armeabi" as Folder name, and click Finish.
  2. Copy javacpp.jar, javacv.jar, opencv.jar, and ffmpeg.jar into the newly created "libs" folder.
  3. Extract all the *.so files from opencv-android-arm.jar and ffmpeg-android-arm.jar directly into the newly created "libs/armeabi" folder, without creating any of the subdirectories found in the JAR files.
  4. Navigate to Project > Properties > Java Build Path > Libraries and click "Add JARs...".
  5. Select all of javacpp.jar, javacv.jar, opencv.jar, and ffmpeg.jar from the newly created "libs" folder.

I'll try it with v 0.8

пятница, 1 августа 2014 г., 17:46:13 UTC+4 пользователь Alexander Ignatov написал:

Олег Осипенко

unread,
Aug 1, 2014, 12:28:06 PM8/1/14
to jav...@googlegroups.com
Just tried to use javacv-08 - same error


пятница, 1 августа 2014 г., 17:46:13 UTC+4 пользователь Alexander Ignatov написал:
Hi. I have got the same message at Eclipse. After spending all day trying to get what was wrong, I downloaded javacv-0.8 and it worked. One thing is critical - make sure you are following instructions from readme.

Samuel Audet

unread,
Aug 2, 2014, 7:44:35 AM8/2/14
to jav...@googlegroups.com
Hi,

On 08/01/2014 10:07 PM, Олег Осипенко wrote:
> I followed instructions on your github page and did all the tricks I've managed to find, but result stays the same.

Have you tried this:

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

Along with a call to Gradle with the "-Dplatform.dependency=android-arm"
option?

Samuel

Олег Осипенко

unread,
Aug 2, 2014, 8:10:59 AM8/2/14
to jav...@googlegroups.com
Hi, Samuel, thanks for reply.
No, I didn't. 
Just to clarify: in which part of build.gradle I have to add "-Dplatform.dependency=android-arm"?

суббота, 2 августа 2014 г., 15:44:35 UTC+4 пользователь Samuel Audet написал:

Samuel Audet

unread,
Aug 2, 2014, 8:21:14 AM8/2/14
to jav...@googlegroups.com
On 08/02/2014 09:10 PM, Олег Осипенко wrote:
> Hi, Samuel, thanks for reply.
> No, I didn't.
> Just to clarify: in which part of build.gradle I have to
> add "-Dplatform.dependency=android-arm"?

I'm not sure.. Does Android Studio and Gradle have a documentation we
could refer to?

Samuel

Samuel Audet

unread,
Aug 2, 2014, 10:16:19 AM8/2/14
to jav...@googlegroups.com
It looks like we may be able to add it to a gradle.properties file as well:
http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html

Samuel

Message has been deleted

Олег Осипенко

unread,
Aug 2, 2014, 11:56:25 AM8/2/14
to jav...@googlegroups.com
Ok, finally I resolved this error.
Steps I made:
  1. In my project module named app in the folder app/src/main I created folder jniLibs and moved there folder armeabi with all *.so files I extracted from ffmpeg-android-arm.jar and opencv-android-arm.jar
  2. In my build.gradle I added these lines to android section 
    productFlavors {
            arm {
                ndk {
                    abiFilter "armeabi"
                }
            }
        }

  3. In dependencies section I include these lines 
  1. compile files('libs/ffmpeg.jar')
        compile files('libs/javacpp.jar')
        compile files('libs/javacv.jar')
        compile files('libs/opencv.jar')

When I tried to use instead of this configuring using maven dependency I got the new error 
08-02 19:54:23.203  25641-25676/oleg.osipenko.agoo E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[oleg.osipenko.agoo.makeVideoService]
    java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.javacpp.avcodec
            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 oleg.osipenko.agoo.utilities.CodeVideoService.onHandleIntent(CodeVideoService.java:74)
            at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.os.HandlerThread.run(HandlerThread.java:60)
     Caused by: java.lang.ClassNotFoundException: org.bytedeco.javacpp.avcodec
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:217)
            at org.bytedeco.javacpp.Loader.load(Loader.java:385)
            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 oleg.osipenko.agoo.utilities.CodeVideoService.onHandleIntent(CodeVideoService.java:74)
            at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.os.HandlerThread.run(HandlerThread.java:60)
     Caused by: java.lang.UnsatisfiedLinkError: Native method not found: org.bytedeco.javacpp.avcodec.AV_CODEC_ID_VP7:()I
            at org.bytedeco.javacpp.avcodec.AV_CODEC_ID_VP7(Native Method)
            at org.bytedeco.javacpp.avcodec.<clinit>(avcodec.java:394)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:217)
            at org.bytedeco.javacpp.Loader.load(Loader.java:385)
            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 oleg.osipenko.agoo.utilities.CodeVideoService.onHandleIntent(CodeVideoService.java:74)
            at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.os.HandlerThread.run(HandlerThread.java:60)

Anyway, finally it works! Now I could sleep in peace ))

суббота, 2 августа 2014 г., 18:16:19 UTC+4 пользователь Samuel Audet написал:

Samuel Audet

unread,
Aug 3, 2014, 6:28:35 PM8/3/14
to jav...@googlegroups.com
On 08/03/2014 12:56 AM, Олег Осипенко wrote:
> 3. In *dependencies *section I include these lines
>
> compile files('libs/ffmpeg.jar')
> compile files('libs/javacpp.jar')
> compile files('libs/javacv.jar')
> compile files('libs/opencv.jar')
>

What happens if you use these lines instead?

compile files('libs/ffmpeg.jar')
compile files('libs/javacpp.jar')
compile files('libs/javacv.jar')
compile files('libs/opencv.jar')
compile files('libs/ffmpeg-android-arm.jar')
compile files('libs/opencv-android-arm.jar')

Samuel

Олег Осипенко

unread,
Aug 4, 2014, 5:23:40 AM8/4/14
to jav...@googlegroups.com
I've tried this and I got an error

понедельник, 4 августа 2014 г., 2:28:35 UTC+4 пользователь Samuel Audet написал:

Samuel Audet

unread,
Aug 4, 2014, 7:12:30 AM8/4/14
to jav...@googlegroups.com
What error do you get?

Олег Осипенко

unread,
Aug 4, 2014, 7:14:11 AM8/4/14
to jav...@googlegroups.com
the same
java.lang.UnsatisfiedLinkError: Couldn't load jniopencv_core from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/oleg.osipenko.agoo-1.apk"],nativeLibraryDirectories=[/data/app-lib/oleg.osipenko.agoo-1, /vendor/lib, /system/lib]]]: findLibrary returned null



понедельник, 4 августа 2014 г., 15:12:30 UTC+4 пользователь Samuel Audet написал:

Samuel Audet

unread,
Aug 4, 2014, 7:37:10 AM8/4/14
to jav...@googlegroups.com
On 08/04/2014 08:14 PM, Олег Осипенко wrote:
the same
java.lang.UnsatisfiedLinkError: Couldn't load jniopencv_core from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/oleg.osipenko.agoo-1.apk"],nativeLibraryDirectories=[/data/app-lib/oleg.osipenko.agoo-1, /vendor/lib, /system/lib]]]: findLibrary returned null

So it looks like they've changed (again) the way they want their users to do things...

Let me know if you figure out the proper way of doing things and what we could do about it, thanks!

Samuel

Олег Осипенко

unread,
Aug 4, 2014, 7:39:47 AM8/4/14
to jav...@googlegroups.com
Android Studio now supports integration with NDK and all *.so files should be located in /jniLibs folder instead of /libs

понедельник, 4 августа 2014 г., 15:37:10 UTC+4 пользователь Samuel Audet написал:

Samuel Audet

unread,
Aug 4, 2014, 7:41:31 AM8/4/14
to jav...@googlegroups.com
On 08/04/2014 08:39 PM, Олег Осипенко wrote:
> Android Studio now supports integration with NDK and all *.so files
> should be located in /jniLibs folder instead of /libs

Ok, and how do we integrate that with Maven?

Олег Осипенко

unread,
Aug 4, 2014, 7:43:23 AM8/4/14
to jav...@googlegroups.com
The answer on this question is beyond my knowledge of Maven and Gradle )

понедельник, 4 августа 2014 г., 15:41:31 UTC+4 пользователь Samuel Audet написал:
Reply all
Reply to author
Forward
0 new messages