2014-06-09 39 views
0

我正在嘗試在Android上使用FFMpeg。首先,我試圖在我的Mac上構建FFMpeg,但我無法做到這一點。我在互聯網上查了很多解決方案,但沒有工作由此我嘗試在Ubuntu 12.04上構建FFMpeg。我嘗試了很多解決方案,最後我發現了this示例,並且我成功構建了它。然後我得到頭文件和.so文件。然後我將它們全部複製到我的Mac上,並嘗試在我的項目中使用它。我將這些文件複製到我的項目中。現在我的項目樹是這個樣子:如何鏈接Android上的.so庫

picture

這裏是我的Android.mk文件:

LOCAL_PATH := $(call my-dir) 

include $(CLEAR_VARS) 
LOCAL_MODULE := avformat 
LOCAL_SRC_FILES := libavformat.so 
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/libavformat 
include $(PREBUILT_SHARED_LIBRARY) 

include $(CLEAR_VARS) 

LOCAL_MODULE := ndksetup 
LOCAL_SRC_FILES := native.c 
LOCAL_LDLIBS := -llog 
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 

include $(BUILD_SHARED_LIBRARY) 

這裏是我的Application.mk文件:

APP_MODULES := ndksetup 
APP_PLATFORM := android-8 
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavformat.so 

這裏是我的natice.c文件:

#include <jni.h> 
#include <string.h> 
#include <android/log.h> 
#include "include/libavcodec/avcodec.h" 
#include "include/libavformat/avformat.h" 

#define DEBUG_TAG "NDKSetupActivity" 

void Java_com_example_ndksetup_MainActivity_printLog(JNIEnv *env, jobject this, 
     jstring logString) { 
    av_register_all(); 
    jboolean isCopy; 
    const char * szLogString = (*env)->GetStringUTFChars(env, logString, 
      &isCopy); 

    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK: %s", szLogString); 

    (*env)->ReleaseStringUTFChars(env, logString, szLogString); 
} 

jint Java_com_example_ndksetup_MainActivity_fibonacci(JNIEnv * env, 
     jobject this, jint value) { 
    if (value <= 1) 
     return value; 
    return Java_com_example_ndksetup_MainActivity_fibonacci(env, this, 
      value - 1) 
      + Java_com_example_ndksetup_MainActivity_fibonacci(env, this, 
        value - 2); 
} 

我得到錯誤

[armeabi] SharedLibrary : libndksetup.so 
/Applications/adt-bundle-mac-x86_64-20140321/sdk/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/michal/Desktop/NDKSetup/obj/local/armeabi/objs/ndksetup/native.o: in function Java_com_example_ndksetup_MainActivity_printLog:/Users/michal/Desktop/NDKSetup/jni/native.c:11: error: undefined reference to 'av_register_all' 
collect2: ld returned 1 exit status 
make: *** [/Users/michal/Desktop/NDKSetup/obj/local/armeabi/libndksetup.so] Error 1 

而且我真的不知道該如何處理它。你能告訴我什麼我做錯了,我該如何解決它?或者,也許有另一種方式來使用.so庫Android在Android

回答

0

LOCAL_SRC_FILESApplication.mk什麼都不做。但是,你應該添加

LOCAL_SHARED_LIBRARIES += avformat 

Android.mkndksetup zection。