2

this question has been raised in different places but none seem to give a simple detailed explanation of what is required.

So far I have built a native binary ffmpeg to be used in android, the build is ok.

I have put the binary in my project /lib/armeabi-v7a/ directory and renamed it to libffmpeg.so so it can be picked up by the packaging system, as advised in other posts.

Now the issue is that the libffmpeg.so or ffmpeg requires some other libraries which are normally in its( ffmpeg) own lib directory. when I run it with Runtime.getRuntime().exec(command) , it calls out for those other libraries which are either not in the right place or have not been picked up at all by android packaging system.

so I copied all the libraries that ffmpeg requires into the same /lib/armeabi-v7a/ but still no success.

Searching in Stackoverflow, i find posts of using jni aproach and others say they can do it without jni. what is the simplest way to use a pre-built binary that requires other libaries in android?

Then there is also the question of Android.mk and Application.mk files, when are they needed, is it only when one is trying to build native C/C++ code in android or should it also be used when pre-built libraries and binaries are involved. And also if I need them for this case where should these files be put in the project?

I'm very new to android please be clear and consice, thanks for sharing some of your wisdom.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
user280026
  • 21
  • 2
  • The executable of FFmpeg offers a high-level interface that the libraries themselves do not offer, so if using the `ffmpeg` executable makes things easier for your application, that would be better than JNI. Please elaborate on your needs. – Samuel Audet Nov 28 '14 at 08:13
  • Hi @Samuel, yes using the ffmpeg executable alone is what I would like, just one file without all the external libs. The project is on hold for now, if you have any additional info, it would be appreciated, thanks. – user280026 Dec 02 '14 at 20:37

1 Answers1

0

I can give you some links:

How to use external C/C++ library file while working with JNI
include .h file into java file in android using jni as source folder of .h file?
multiple (my and 3rd-party) native libraries in Android NDK
Android NDK - make two native shared libraries calling each other

First of all, how do you want to call the native code?

You have 2 options:

1) Call library functions via a wrapper: a class that defined a set of native functions. You will have to convert data structures between the Java representation and the C representation. A Java object maps to a very specific kind of C data structure, and C structures cannot be normally accessed from Java. So for each invoked C/C++ function there is a wrapper that implements a Java native function.

2) You can invoke a shell command. Android is Linux, and you can communicate to it via adb shell. You can pass command-line arguments, write/read to/from stdin/stdout of the started process. You also can pass data to/from the started process via the file system. For example, this is how to use su on a rooted device: execute shell command from android

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • I would please like to know how to add the other libraries or .so files which the binary in question needs to run, that is where I, stuck, because I already have a built library, do I still need all the header files? – user280026 Nov 26 '14 at 12:07
  • I'm now using System.loadlibrary(avdevice) for example to load the needed libraries and it seems to have found there location, so let me see how for that goes. I woudd give the jni method a try no doubt when I have some C/C++ code I would to use on android – user280026 Nov 26 '14 at 12:30
  • Please the question is still open, it will help others if someone could put together in simple clear language what it takes, I'm also sure that there could/should be more than one method to do this – user280026 Nov 26 '14 at 15:17
  • http://stackoverflow.com/a/10367658/755804 You put a copy of .so into the jni folder and write a special .mk file. The trick is that you can create any number of modules in one .mk, either by including other .mk files or copying&pasting their source into one .mk. – 18446744073709551615 Nov 27 '14 at 09:25
  • 1
    I had to build the native bin again, but this time with enable--static in the build.sh file, then place it in the libs folder of my project and rename it into lib-something.so, the rest is done by the packaging system. When built static it has all it needs built into it. I'm really trying to understand the jni method though, but it hasn't clicked yet . – user280026 Nov 27 '14 at 15:59