问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/27144101/using-a-prebuilt-native-binary-in-android-app