java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
First problem
Your versions don't match. org.bytedeco.javacpp
in version 0.10
is from Dec 2014, while all your other versions are from May 2016. You need to use version 1.2
of org.bytedeco.javacpp
, or better yet, update all dependencies to the latest version.
You can see the versions here:
org.bytedeco.javacpp-presets » opencv
org.bytedeco.javacpp-presets » ffmpeg
org.bytedeco » javacv
org.bytedeco » javacpp
Second problem
You include the dependencies for Java code only, but you don't include the dependencies for native code (both opencv and ffmpeg are native libraries). You need to include opencv-platform
and ffmpeg-platform
instead:
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv-platform</artifactId>
<version>3.4.1-1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg-platform</artifactId>
<version>3.4.2-1.4.1</version>
</dependency>
This will make Maven download and include opencv and ffmpeg libraries for Android, Linux, MacOS and Windows, both x86 and x64.
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
Actual cause of error is different versions of dependencies. That's why javacpp
package failed during mapping of classes.
Follow these step to resolve this problem:
- Download latest version of Javacv library package from here
Copy these three
.jar
files intolibs
folderffmpeg.jar
javacv.jar
javacpp.jar
Create
jniLibs
folder inapp\src\main
Now, create four different folders for different architectures
arm64-v8a
armeabi
armeabi-v7a
x86
Change extension of these two files
ffmpeg-android-arm.jar, ffmpeg-android-x86.jar
to.zip
then unzip both folders and Copy.so
files for each architecture and paste in its respected directory. Your resultant directory should be look like thisAdd
.jar
dependencies in your gradle file as follows:implementation files('libs/ffmpeg.jar') implementation files('libs/javacpp.jar') implementation files('libs/javacv.jar')```
Thanks for reading :)