bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.58k stars 1.58k forks source link

java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil in Marshmallow #245

Closed boybeak closed 8 years ago

boybeak commented 9 years ago
mFrameRecorder = new FFmpegFrameRecorder(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath() + File.separator + "new.mp4", 480, 480, 1);

crash happened in this code after i update my nexus5 to Marshmallow,and it works fine before.And the error log below:

10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime: FATAL EXCEPTION: main
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime: Process: com.beak.petsfbi, PID: 22095
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime: java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at java.lang.Class.classForName(Native Method)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at java.lang.Class.forName(Class.java:324)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at org.bytedeco.javacpp.Loader.load(Loader.java:390)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at org.bytedeco.javacpp.Loader.load(Loader.java:358)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at org.bytedeco.javacpp.avcodec$AVPacket.<clinit>(avcodec.java:1407)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at org.bytedeco.javacv.FFmpegFrameRecorder.<init>(FFmpegFrameRecorder.java:149)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at com.beak.petsfbi.activity.VideoRecorderActivity.startRecord(VideoRecorderActivity.java:177)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at com.beak.petsfbi.activity.VideoRecorderActivity$1.onClick(VideoRecorderActivity.java:57)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at android.view.View.performClick(View.java:5198)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:21147)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-06 16:15:28.015 22095-22095/com.beak.petsfbi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
phajduk commented 9 years ago

+1 I have the same problem.

saudet commented 9 years ago

Did they break backward compatibility? Is there any info on that from Google?

boybeak commented 9 years ago

@saudet My android studio version is 1.4, compileSdkVersion 23, buildToolsVersion 23.0.0

boybeak commented 9 years ago

@saudet I've been tried all the solution in #133 ,but not working

boybeak commented 9 years ago

@saudet Similar problem find here:https://code.google.com/p/android-developer-preview/issues/detail?id=3028 , it seems no solution.

tomerhatav commented 9 years ago

+1 I have the same problem here. :(

boybeak commented 9 years ago

@tomerhatav @saudet @phajduk I find a official page maybe useful https://developer.android.com/intl/ko/about/versions/marshmallow/android-6.0-changes.html#behavior-runtime

zavadpe commented 9 years ago

As boybeak wrote, official release page explicitly refers to loading of shared libraries with text relocations:

On previous versions of Android, if your app requested the system to load a shared library with text relocations, the system displayed a warning but still allowed the library to be loaded. Beginning in this release, the system rejects this library if your app's target SDK version is 23 or higher.

saudet commented 9 years ago

@zavadpe If you know what we need to do for that, please update the instructions on this wiki page: https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments

zavadpe commented 9 years ago

I did only simple workaround for now as suggested in the text I quoted - I decreased target SDK to 22 in my project. Long term solution requires ffmpeg libraries (I saw avutil causing an error) to be built without text relocations but I have no experience how to do that. But developer site suggests to go here where good instructions can be found how to find those textrels. However I may take look at it later.

ryango commented 9 years ago

What version of ffmpeg is being used in the binary distro of javacv? According to http://stackoverflow.com/questions/32346402/libavcodec-so-has-text-relocations there are 2 commits that change how android is built https://github.com/FFmpeg/FFmpeg/commit/f963f80399deb1a2b44c1bac3af7123e8a0c9e46 https://github.com/FFmpeg/FFmpeg/commit/cb416a7d795414aaa534c27943bda0d3aef3b5a1 Looks like they have been around since 2.6?

ryango commented 9 years ago

Actually not since 2.6. Seems like it's only in unreleased master. Pulling latest Ffmpeg master and compiling with ndk-r10e in checking avcodec.so. Looks like it'll be with 2.9 when they gm that release. Having linker issues now with the jni when I just swap out the .so files (expected). I guess I have to build javacv, javacpp and ffmpeg from scratch.

ryango commented 9 years ago

Haha I'm just going to keep spamming here, apologies. Looks like has been in since 2.6. Verified building with r10e and 2.8 release HEAD I get no text relocations in avcodec. Same linker issue with the jni. Will try to rebuild all the deps, though you should consider pulling latest ffmpeg if you haven't and building the android libs before everyone who uses javacv in android comes calling.

saudet commented 9 years ago

JavaCV 1.1 links with FFmpeg 2.8.1, and that doesn't work? What is the difference between your binaries and the release?

ryango commented 9 years ago

So our configure is likely a little different, not sure if that would do it. Combining my ffmpeg .so files with the rest in the JavaCV 1.1 distro yields

java.lang.UnsatisfiedLinkError: dlopen failed: cannot find "libavutil.so" from verneed[0] in DT_NEEDED list for "/data/app/<packagename>/lib/arm/libjniavcodec.so

Running arm-linux-androideabi-readelf interestingly shows no text relocations for my binaries but they are present for yours. Maybe theres an encoder enabled that causes that? I'm kinda feeling around in the dark right now as I'm not too experienced with native builds. We've had a working build for 2 years that we've remained as hands off as possible with since it just worked.

./configure \
--prefix=$HOME/android \
--enable-shared \
--enable-runtime-cpudetect \
--disable-encoders \
--disable-bsfs \
--disable-decoders \
--enable-decoder=ac3 \
--enable-encoder=libvorbis \
--enable-muxer=matroska \
--enable-muxer=webm \
--enable-decoder=binkaudio_dct \
--enable-decoder=binkaudio_rdft \
--disable-parsers \
--enable-libvpx --enable-encoder=libvpx_vp8 --extra-cflags="-I$thisdir/vpx/include" --extra-ldflags="-L$thisdir/vpx/lib" \
--enable-libvorbis --extra-cflags="-I$prefixdir/include " --extra-ldflags="-L$prefixdir/lib" \
--disable-outdevs \
--disable-indevs \
--disable-filters \
--enable-cross-compile \
--cc=$ANDROID_BIN/arm-linux-androideabi-gcc \
--sysroot=$ANDROID_ROOT \
--target-os=linux \
--arch=arm \
--extra-cflags="-DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mfpu=neon -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300" \
--extra-ldflags="-nostdlib -Wl,--fix-cortex-a8 -Werror=implicit-function-declaration" \
--extra-libs="-lgcc -ldl -lz -lm -lc -llog" \
--disable-stripping \
--disable-symver \
--disable-programs
Iqra786 commented 8 years ago

Google already closed this issue: https://code.google.com/p/android-developer-preview/issues/detail?id=3028 FFmpeg also closed this issue: They said this intended functionality and not a bug. https://trac.ffmpeg.org/ticket/4928 I am stuck.

saudet commented 8 years ago

It seems to be a problem with one of the dependent libraries. So, FFmpeg rebuilt without any of them shouldn't cause this issue.

Iqra786 commented 8 years ago

I don't have knowledge how to build new binary.
Following ref from the https://trac.ffmpeg.org/ticket/4928 discussion

"It should be emphasized that --disable-asm does not fix anything, it just creates horribly slow FFmpeg binaries."

alexbatashev commented 8 years ago

As stated here (in russian) some libraries were excluded from Marshmallow. For example, OpenSSL was replaced with BoringSSL. May this cause crash? FFmpeg can work with SSL, so... Another version is stated here

@ryango java.lang.UnsatisfiedLinkError: dlopen failed: cannot find "libavutil.so" from verneed[0] in DT_NEEDED list for "/data/app/<packagename>/lib/arm/libjniavcodec.so It's not surprising. There's no such file. Actually, there are no javacv files at all. But there are Realm files (which is cinnected to my project). That makes me think it is something wrong with the jar itself. Did you try putting .so files to /src/main/jniLibs?

ongakuer commented 8 years ago

@ryango I have built javacpp-presets (1.2-SNAPSHOT) , FFmpeg (2.8.4/2.8.5) It worked in Marshmallow and libavcodec.so has no text relocations!

ryango commented 8 years ago

@ongakuer well done!

ongakuer commented 8 years ago

I try to built ffmpeg 2.8.1( custom cppbuild ) with javacpp (1.2-SNAPSHOT) and still worked in Marshmallow.

It's seems weird…

javacpp 1.1, javacpp-presets 1.1, FFmpeg 2.8.1, Ubuntu 14.04 libavcodec.so has text relocations.

javacpp 1.2-SNAPSHOT, javacpp-presets 1.2-SNAPSHOT, FFmpeg 2.8.1/2.8.4/2.8.5, OS X 10.11.3 libavcodec.so has no text relocations.

saudet commented 8 years ago

@ongakuer Maybe it has something to do with the changes I've made for issue https://github.com/bytedeco/javacpp-presets/issues/133?

ongakuer commented 8 years ago

@saudet Maybe you are right,Thanks.

tomerhatav commented 8 years ago

@saudet will you release anytime soon a new version of javacv that fixes the text relocations bug?

saudet commented 8 years ago

@tomerhatav Well, if you could make a branch that works with JavaCPP 1.1, I'd release that right away, sure.

coralinejones1985 commented 8 years ago

Hi, I've got this error too. So...to avoid this error I shoud build ffmpeg from scratch?

zella commented 8 years ago

+1, how to fix this?

saudet commented 8 years ago

I've uploaded SNAPSHOT binaries here: https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.2-SNAPSHOT/ https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp-presets/ffmpeg/2.8.5-1.2-SNAPSHOT/ https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacv/1.2-SNAPSHOT/ I haven't tested them, so would be happy to know if they work or not! Thanks for any feedback.

ongakuer commented 8 years ago

@saudet It not work…

2016-02-23 11 55 55

saudet commented 8 years ago

Thanks for testing! So, when it gets built on OS X, there's no text relocations? Is it a bug in the Android NDK for Linux?

ongakuer commented 8 years ago

I built it on OS X with my custom cppbuild (only enable x264). I not sure third party libraries(openh264,lame,opencore-amr) may cause this.

I will build the latest javaccp-ffmpeg with default cppbuild later.

ongakuer commented 8 years ago

@saudet Yes! There's no text relocations when built it on OS X. It work well on Marshmallow. Here is the javacpp-ffmpeg library(FFmpeg 3.0) target.zip

coralinejones1985 commented 8 years ago

@ongakuer will it work on x86 devices?

ongakuer commented 8 years ago

@coralinejones1985 Sorry,I just build for arm.

saudet commented 8 years ago

@ongakuer Which version of yasm are you using? Here I get

$ yasm --version
yasm 1.3.0

Maybe that's where the difference lies...

ongakuer commented 8 years ago

@saudet yasm 1.3.0 ……

fuyacho-takatsuji commented 8 years ago

I am new to javacv and ran into the same problem when I tried RecordActivity.java. Is the problem fixed with @ongakuer target.zip?

fuyacho-takatsuji commented 8 years ago

Hi, I imported @ongakuer target.gz( .so files and 2 jar files) to Studio and tried RecordActivity.java.
I have the following error... It says "bit_rate" method is not found. Any clue on this?


Process: javacv.bytedeco.org.recordactivirycv, PID: 571 java.lang.NoSuchMethodError: No virtual method bit_rate(I)Lorg/bytedeco/javacpp/avcodec$AVCodecContext; in class Lorg/bytedeco/javacpp/avcodec$AVCodecContext; or its super classes (declaration of 'org.bytedeco.javacpp.avcodec$AVCodecContext' appears in /data/app/javacv.bytedeco.org.recordactivirycv-1/base.apk) at org.bytedeco.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:369) at org.bytedeco.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:288) at javacv.bytedeco.org.recordactivirycv.RecordActivity.startRecording(RecordActivity.java:200) at javacv.bytedeco.org.recordactivirycv.RecordActivity.onClick(RecordActivity.java:493) at android.view.View.performClick(View.java:5204) at android.view.View$PerformClick.run(View.java:21153) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

ongakuer commented 8 years ago

@fuyacho-takatsuji
Don't use JavaCV 1.1 Release Version. Download latest JavaCV (https://github.com/bytedeco/javacv/commit/28065a0c646e13ce8e588df0630c53f07924c18b) from github and import to your project. Maybe you need remove unused file.

PS: I move .so files to armeabi-v7a

fuyacho-takatsuji commented 8 years ago

@ongakuer , Thanks for the quick response. I downloaded the latest javaCV files, but got a lot of errors when I compiled all the files on Studio. As you said I surely need to remove unnecessary files. Would you help how to find the necessary files/remove unnecessary files?

I am new to git hub as well...

ongakuer commented 8 years ago

@fuyacho-takatsuji
I keep these files :

coralinejones1985 commented 8 years ago

@ongakuer Were you using android-ndk-r10e to build ffmpeg? Can you, please, show how your .sh file looks like?

ongakuer commented 8 years ago

@coralinejones1985 Yes, Android-ndk-r10e. I use javacpp to build ffmpeg. javaccp cppbuild.sh javaccp-ffmpeg cppbuild.sh

@saudet Android-ndk-r11 has released.

Updated YASM to version 1.3.0

fuyacho-takatsuji commented 8 years ago

@ongakuer Thank you very much for your advice. I commented out some java.beans stuff in FrameGrabber.java to have the code run through Studio. I can now record .mp4 file on both KitKat and Marshmallow.

saudet commented 8 years ago

Thanks @ongakuer!

I've narrowed it down to libx264. If I build without specifying --enable-libx264, I get no text relocations. Indeed, it's something they seem to have fixed very recently: [x264-devel] arm: Eliminate text relocations in asm https://mailman.videolan.org/pipermail/x264-devel/2016-January/011527.html So let me try with the latest source code...

saudet commented 8 years ago

Yes, it's fixed with FFmpeg 3.0 and latest libx264!

coralinejones1985 commented 8 years ago

I've built 1.2-SNAPSHOT (javacv, javacpp, ffmpeg and opencv jars) to get "no relocations"-version, but still got ones. Also some errors appeared: Failed to load class org.bytedeco.javacv.FFmpegFrameRecorder NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.javacpp.avutil UnsatisfiedLinkError: dlopen failed: /lib/x86/libavcodec.so: has text relocations UnsatisfiedLinkError: dalvik.system.PathClassLoader couldn't find "libgnustl_static.so"

I have no idea of what am I doing wrong..

saudet commented 8 years ago

But it wasn't fixed for android-x86. I had to disable asm code for libopenh264 and libx264 to get binaries without text relocations.

saudet commented 8 years ago

I've uploaded SNAPSHOT binaries here: https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.2-SNAPSHOT/ https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp-presets/ffmpeg/3.0-1.2-SNAPSHOT/ https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacv/1.2-SNAPSHOT/ They should work, but please let me know if you encounter any problems! Thanks