尝试通过JNI调用MPEG4Writer.o时,演示失败

时间:2014-04-25 02:05:06

标签: android android-ndk java-native-interface mpeg-4 mediamuxer

我正在JellyBean(Android4.2.2)上构建我的应用程序演示,演示的一个模块是将h264流写入mp4文件。由于MPEG4Writer在源代码中完成了这项工作,所以我尝试通过JNI调用它。

编译完源代码后,我得到了MPEG4Writer.o文件。在我的第一步中,我只想尝试这种方式。所以我编写了JNI文件,这很简单,只需创建一个MPEG4Writer类的新实例:

#include <string.h>
#include <jni.h>
#include <android/log.h>
#include "MPEG4Writer.h"

#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "MPEG4Writer", __VA_ARGS__)


jint Java_com_examole_brendontest_MainActivity_setup
    (JNIEnv *env, jclass cls) {

     mWriter = new MPEG4Writer("/sdcard/encode_manual.mp4");
     if (mWriter != NULL)
             LOGV("IT WORKS!!");

     return 1;
}

Android.mk文件:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE                    := JNIMPEG4Writer
LOCAL_STATIC_LIBRARIES  := MPEG4Writer
LOCAL_LDLIBS                    := -llog
LOCAL_SRC_FILES                 := JNIMPEG4Writer.cpp

include $(BUILD_SHARED_LIBRARY)

然后我用Java调用函数:

static{
    System.loadLibrary("JNIMPEG4Writer");
}
 public static native int setup();

构建项目时可以,但是当我运行它时它就会关闭。日志是:

04-25 09:17:24.302: E/AndroidRuntime(31737): FATAL EXCEPTION: main
04-25 09:17:24.302: E/AndroidRuntime(31737): java.lang.ExceptionInInitializerError
04-25 09:17:24.302: E/AndroidRuntime(31737):    at java.lang.Class.newInstanceImpl(Native Method)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at java.lang.Class.newInstance(Class.java:1319)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2122)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.app.ActivityThread.access$600(ActivityThread.java:148)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.os.Looper.loop(Looper.java:137)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at android.app.ActivityThread.main(ActivityThread.java:5102)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at java.lang.reflect.Method.invokeNative(Native Method)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at java.lang.reflect.Method.invoke(Method.java:511)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at dalvik.system.NativeStart.main(Native Method)
04-25 09:17:24.302: E/AndroidRuntime(31737): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load JNIMPEG4Writer from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.brendontest-2.apk,libraryPath=/data/app-lib/com.example.brendontest-2]: findLibrary returned null
04-25 09:17:24.302: E/AndroidRuntime(31737):    at java.lang.Runtime.loadLibrary(Runtime.java:365)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at java.lang.System.loadLibrary(System.java:535)
04-25 09:17:24.302: E/AndroidRuntime(31737):    at com.example.brendontest.MainActivity.<clinit>(MainActivity.java:12)
04-25 09:17:24.302: E/AndroidRuntime(31737):    ... 15 more

我真的不知道。如果这种方式使用MPEG4Writer可能吗?有谁有想法吗?谢谢!

0 个答案:

没有答案