I have recently been getting the following error by attempting to start an instance of JavaCV's FFmpegFrameGrabber:
java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at org.bytedeco.javacpp.Loader.load(Loader.java:413)
at org.bytedeco.javacpp.Loader.load(Loader.java:381)
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2597)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:386)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:380)...
While solutions to this problem exist, none worked for me.
Through many trials i have discovered that weirdly enough, if i do not include Realm in my project, i no longer receive this error.
Here is the part of my build.gradle file in which I include all of these libraries:
compile group: 'org.bytedeco', name: 'javacv', version: '1.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-x86'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-x86'
// ORM
compile 'io.realm:realm-android:0.87.2' // Tested NOT OK - Causes JavaCV to crash
//
I am thinking that there may be a solution to this problem that i am not aware of. I found no mention anywhere on the internet about library incompatibility or why this behaviour may occur.
I will edit this post with any additional details that anyone might need.
Any help would be greatly appreciated.
EDIT
I attempted to apply the fix described here.
Now my packaging options look like this:
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'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
exclude "lib/arm64-v8a/librealm-jni.so"
}
Unfortunately, this change has no effect. I'm still stuck.
With the help of one of my coleagues i have been able to solve this issue.
In adition to the steps described in the question, we:
Copyed all of the .so files in the app/src/main/jniLibs/armeabi and app/src/main/jniLibs/armeabi-v7a folders
Added
ndk {
abiFilters "armeabi-v7a"
}
to the defaultConfig part of the module's build.gradle file
Added
lintOptions {
abortOnError false
}
to the android part of the module's build.gradle file
I will try to provide further clarifications to anyone that needs them if i am able.
Firstly this issue occurs because of Gradle doesn't resolve dependencies properly from maven profile ..In my case only x86 depdendecies shipped to APK. that means code above works only on x86 cpu architecture. solution should be done on Android Studio. but as workaround I did this:
Download binary javacv-platform-1.3.1-bin.zip. It's from: https://github.com/bytedeco/javacv
Inside directory javacv-bin copy these jars to new directory
ffmpeg-android-arm.jar
opencv-android-arm.jar
ffmpeg-android-x86.jar
opencv-android-x86.jar
For 2.1 2.2 files, Extract these jars and go to lib then or armeabi. Then copy all *.so files into your project under:
app/src/main/jniLibs/armeabi/
app/src/main/jniLibs/armeabi-v7a/
you might do the same with 2.3 * 2.4 jars by copying dependencies into app/src/main/jniLibs/x86/ . just check your apk if it really doesn't have them.
That's it.
Related
Background:
I'm working on creating a messaging library that basically abstracts GCP Pub/Sub. Accordingly, I am creating a fat JAR with relocated packages, and this fat JAR is imported in other projects. The point to isolate the fat JAR's dependencies from those of the importing projects.
When I test this locally from an IDE, the fat JAR works fine. However, when I export a project to a JAR and run it, I get the following error.
I have also checked the logs and found the following which I have found in this issue that these configurations are correct.
Is there something wrong with the address provided here, or should I configure anything on my end?
These are the dependencies I'm fetching for the library via Gradle.
implementation group: 'io.grpc', name: 'grpc-okhttp', version: '1.40.1'
implementation group: 'io.perfmark', name: 'perfmark-impl', version: '0.25.0'
implementation group: 'com.google.cloud', name: 'google-cloud-pubsub', version: '1.114.6'
implementation group: 'io.grpc', name: 'grpc-context', version: '1.42.2'
implementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jApiVersion}"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
Thanks.
I am working on a Dubbo project and when I digging a little deep into its source code. I found these code in Dubbo's source code:
I think this shows that my project missing the org.jboss.*package
(IDEA has mark these packages in red)
But somehow this project still working, doesn't it supposed to not working due to it has some package missing?
By the way my project is organized by gradle and the build.gradle is like this:
dependencies
{
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile group: 'org.apache.dubbo', name: 'dubbo-spring-boot-starter', version: '2.7.8'
compile group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.6.2'
compile group: 'org.apache.curator', name: 'curator-framework', version: '5.1.0'
}
If this wouldn't be some library's de-compiled byte-code but your application's source code, this would rather be an issue. And it's not missing anything, but Gradle will pull in org.jboss.netty on demand, which will then pull in another 8 libraries, which may evetually even pull in further libraries.
I am trying to run CnnSentenceClassification from deeplearning4j example. I moved this file to my Gradle project. When I run the class from the eclipse it works fine. However when I run it from ./gradlew run I get following error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at
main.CnnSentenceClassification.main(CnnSentenceClassification.java:75)
Caused by: java.lang.RuntimeException:
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException:
Please ensure that you have an nd4j backend on your classpath. Please
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6089)
at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:201)
... 1 more
Caused by:
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException:
Please ensure that you have an nd4j backend on your classpath. Please
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:258)
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6086)
... 2 more
I checked and nd4j-api-0.9.1.jar is in my classpath. This is my build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
repositories {
jcenter()
}
mainClassName="main.CnnSentenceClassification"
dependencies {
compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '0.9.1'
compile group: 'org.deeplearning4j', name: 'deeplearning4j-nlp', version: '0.9.1'
testCompile group: 'org.nd4j', name: 'nd4j-native-platform', version: '0.9.1'
compile group: 'org.nd4j', name: 'nd4j-api', version: '0.9.1'
compile "org.slf4j:slf4j-simple:1.7.25"
compile "org.slf4j:slf4j-api:1.7.25"
}
I was having the same problem. You need an ND4J backend, which means updating your dependency tree.
For Maven builds, add the following dependency to your project's pom:
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>0.9.1</version>
</dependency>
For Gradle builds, just add the following line in your dependencies:
compile "org.nd4j:nd4j-native:0.9.1"
This native backend uses the CPU for computations.
There is another dependency for a CUDA-enabled graphics card.
I found this link helpful:
DL4J Performance Debugging
Edit: new link is here. https://deeplearning4j.konduit.ai/config/backends
Old content below:
You have test scope on the nd4j backend. An nd4j backend is NEVER optional.
https://nd4j.org/backend.html
The error is right in the message. We even give you a link with an explanation right in the stack trace.
I'm trying to exclude some modules from my build.gradle file but it(code1 and code2) still downloads the excluded files.
code 1:
compile (group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.7') {
exclude group: 'com.amazonaws', module: 'aws-java-sdk-machinelearning'
}
code 2:
compile (group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.7') {
exclude module: 'aws-java-sdk-machinelearning'
}
when I tried using the following code,
configurations {
compile.exclude module: 'aws-java-sdk-machinelearning'
}
it excludes the files but I don't want to use this method to exclude files
I second/confirm with #Opal that code1 works fine in Gradle 2.13.
What is likely happening is that you have some other (maybe non-aws) dependency, that may be transitively using aws-java-sdk which then brings in the machine-learning dependency. Which is why, it works fine when you do a global exclude, but not when you do a local exclude on just aws-java-sdk.
Try running gradlew dependencies --configuration=compile to get a tree of dependencies, including transitives, to check which dependency might be bringing in aws-java-sdk-machinelearning
I have downloaded JasperReports jars (jasperreports-5.6.0-project.zip from here) and toke all the jars in the dist folder. These are the files I added to my project:
jasperreports-5.6.0.jar
jasperreports-applet-5.6.0.jar
jasperreports-fonts-5.6.0.jar
jasperreports-javaflow-5.6.0.jar
But when I try my code I always get this error:
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
UPDATE 1
I solved that error and I have a lot of more missing jars. Please tell me all the additional jars needed to use JasperReports.
Ok, as I said I added the jars in the dist folder of the downloaded zip (as showed in the question) to my project and to resolve all the problems I had, I added the next jars from the lib folder to my project:
JasperReports 5.6.0 - ...
...poi-3.7-20101029.jar
...commons-beanutils-1.8.0.jar
...commons-collections-3.2.1.jar
...commons-digester-2.1.jar
...commons-javaflow-20060411.jar
...commons-logging-1.1.1.jar
...groovy-all-2.0.1.jar
...iText-2.1.7.js2.jar
...jcommon-1.0.15.jar
...jfreechart-1.0.12.jar
Hope this helps someone!
these are gradle dependencies i needed to make Jasper Report work in Spring Boot:
// https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports
compile group: 'net.sf.jasperreports', name: 'jasperreports', version: '5.0.1'
// https://mvnrepository.com/artifact/commons-logging/commons-logging
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.2'
// https://mvnrepository.com/artifact/com.lowagie/itext
compile group: 'com.lowagie', name: 'itext', version: '2.1.7'
Hope it helps someone.