--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
If you used the bambuser ffmpeg source package, you need to apply the
included patches, too (which is done by extract.sh, as explained in the
README file). Patch #1, "Set the soname to be $(SLIBNAME) instead of
$(SLIBNAME_WITH_MAJOR)", takes care of exactly this issue, by making the
libraries depend on each other via sonames without version number.
// Martin
On Mon, 17 Oct 2011, Wil Hadden wrote:
Yes, the patch I mentioned doesn't work around that issue (which is
present for all cases where one .so depends on another .so in the same
apk), it only changes the soname that the library exposes (making
libraries depend on "libavutil.so" instead of "libavutil.so.50".
The issue with transitive dependencies is easy to resolve by simply
loading them in reverse order, e.g.
System.loadLibrary("avutil");
System.loadLibrary("avcore");
System.loadLibrary("avcodec");
System.loadLibrary("yourlib");
This issue is also explained in the android NDK docs (in reference to a
similar case) in docs/CPLUSPLUS-SUPPORT.html.
This way of loading libs with transitive dependencies works since Android
1.6.
For 1.5, the bambuser ffmpeg package contains another workaround, patch
#2, which adds the possibility to add a prefix to the sonames. The build
script in that ffmpeg source package adds the prefix
/data/data/com.bambuser.broadcaster/lib/ to the sonames, so that the
linker explicitly looks for that path regardless of library search paths.
This obviously only works as long as the app is installed into this path
(which afaik is the only one for devices running 1.5), but doesn't seem to
harm devices running newer versions (which are handled by loading them in
reverse order as described above).
// Martin
As far as I know, it shouldn't blow up in the future either - as I said,
we're using it in production (together with the reverse loading order) on
both 1.5 and a lot of newer devices.
Namely, when using the reverse loading order, it first loads the library
(by looking through the paths for application libraries, finding it in the
app directory and telling the system to load exactly that file). When that
library is loaded (e.g. libavutil.so), and loading the next library
(libavcodec.so), libavcodec.so will have a dependency on
/data/data/app.identifier/lib/libavutil.so. On 1.6 and newer, the dynamic
linker will notice that there's already a "libavutil.so" loaded into the
process, which satisfies the dependency. On 1.5, it doesn't realize
there's already a library loaded with the same name, but it tries to look
for a library with the exact name specified,
/data/data/app.identifier/lib/libavutil.so, which hopefully is found
(assuming all 1.5 devices install the apps into that path).
Therefore, as far as I know, this setup works for all devices, both 1.5
and later.
> I have also the reverse load order trick which is a lot nicer, though
> it does add a sort of link dependency in your code, which is still
> nicer than the alternative. Is it not possible to still have a
> circular dependency that this would not solve?
Libraries should never have circular dependencies - they would be kind of
hard to produce, too, and I'm not sure how a normal dynamic linker would
handle that either. Do you really have such a concrete case?
> Sorry for all the questions, but I went through this recently and
> it's nice to know how to work around it!
>
> The biggest issue I foresaw with the reverse order load though, and
> correct me if I'm wrong as I never tried this out, but does this not
> mean that every lib you load would need a JNI_OnLoad at a bare
> minimum, whereas if you could somehow load the necessary libs as a
> dependency then there would not be a need for individual JNI_OnLoads?
No, not at all. You don't need a JNI_OnLoad function. If it isn't present,
there will be a informative message about it not being found, but
System.loadLibrary() still loads the library just fine.
As I said, the binaries produced by the bambuser ffmpeg build script are
the exact binaries used in production there, without any JNI_OnLoad
functions added or anything. And we're not aware of any issue related to
loading of these libraries.
// Martin