[英]How to link and call function of prebuild static native library from android studio
I need to change pitch and time stretching of an audio.我需要更改音频的音高和时间拉伸。 For this I am using prebuild static library.为此,我使用预构建静态库。 Currently I am having libZtxAndroid.a static library and corresponding header file which contains function declaration.目前我有 libZtxAndroid.a 静态库和包含函数声明的相应头文件。 But I don't know how to load this library in my android studio app and call native function from java code.但我不知道如何在我的 android studio 应用程序中加载这个库并从 java 代码调用本机函数。 I explored many links and tried to load this library.我浏览了许多链接并尝试加载这个库。 But all attempts are failed.但是所有的尝试都失败了。 This is the one link which I have tried last time https://tariqzubairy.wordpress.com/2012/03/12/use-of-prebuild-static-library-compiled-with-android-toolchain/这是我上次尝试过的一个链接https://tariqzubairy.wordpress.com/2012/03/12/use-of-prebuild-static-library-compiled-with-android-toolchain/
Also I am using FFMPEG shared library and MP4Parser ( https://github.com/sannies/mp4parser ) library in this app for adding water mark to video and merging audio respectively.此外,我在此应用程序中使用 FFMPEG 共享库和 MP4Parser ( https://github.com/sannies/mp4parser ) 库分别为视频添加水印和合并音频。 Can any one help from basics.任何人都可以从基础知识中获得帮助。
You need to do several things:你需要做几件事:
If you have something like this in android:如果你在android中有这样的东西:
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz ) Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz )
where Java_comp_example_hellojni_HelloJni is your project name, you have to do from Java, assuming the name of your lib is libmylib.so:其中 Java_comp_example_hellojni_HelloJni 是您的项目名称,您必须从 Java 开始,假设您的 lib 名称是 libmylib.so:
public class HelloJni {
static {
System.LoadLibrary('mylib');
}
public native stringFromJni();
}
Note that the native library name does not need the lib prefix and the .so suffix.请注意,本机库名称不需要 lib 前缀和 .so 后缀。 Note also that you do not need any header file from C++, you just load the library from Java and declare a native function.另请注意,您不需要来自 C++ 的任何头文件,您只需从 Java 加载库并声明本机函数。 The library should be already compiled and in the right directory before the Java project uses it.在 Java 项目使用它之前,该库应该已经编译并位于正确的目录中。
Be careful at loading: if you use the shared version of the standard library, you will also need to add it to your static { section in Java for loading it, before your library.加载时要小心:如果您使用标准库的共享版本,您还需要将它添加到 Java 中的静态 { 部分以在您的库之前加载它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.