本文2017-3-11 參考了: http://blog.csdn.net/huweijian5/article/details/52883969 基本環(huán)境: 1. 操作系統(tǒng):Windows10 64位; 2. Android Studio 2.3,,64位。 3. Android NDK開發(fā)包:直接使用Android Studio安裝NDK,。(需要梯子) 4.按照上述三編譯好了ffmpeg相關(guān)的.so共享庫文件和按照上述一編譯好的NDK Hello World程序 第一步:拷貝so文件 將“一,、環(huán)境搭建,,NDK Hello World”的工程中項目下的\app\src\main建立jniLibs目錄,再在該目錄下建立armeabi目錄,,將avcodec-57.so,、avformat-57.so、avutil-55.so,、swresample-2.so,、swscale-4.so拷貝到該目錄下。 第二步:修改CmakeList.txt文件 cmake_minimum_required(VERSION 3.4.1) set(lib_src_DIR ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}) include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include) add_library(avcodec-57_lib SHARED IMPORTED) set_target_properties(avcodec-57_lib PROPERTIES IMPORTED_LOCATION ${lib_src_DIR}/libavcodec-57.so) add_library(avformat-57_lib SHARED IMPORTED) set_target_properties(avformat-57_lib PROPERTIES IMPORTED_LOCATION ${lib_src_DIR}/libavformat-57.so) add_library(avutil-55_lib SHARED IMPORTED) set_target_properties(avutil-55_lib PROPERTIES IMPORTED_LOCATION ${lib_src_DIR}/libavutil-55.so) add_library(swresample-2_lib SHARED IMPORTED) set_target_properties(swresample-2_lib PROPERTIES IMPORTED_LOCATION ${lib_src_DIR}/libswresample-2.so) add_library(swscale-4_lib SHARED IMPORTED) set_target_properties(swscale-4_lib PROPERTIES IMPORTED_LOCATION ${lib_src_DIR}/libswscale-4.so) add_library( native-lib SHARED src/main/cpp/native-lib.cpp ) find_library(log-lib log ) target_link_libraries( native-lib ${log-lib} avcodec-57_lib avformat-57_lib avutil-55_lib swresample-2_lib swscale-4_lib ) 第三步:修改native-lib.cpp文件 #include <jni.h> #include <string> extern "C"{ #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libswscale/swscale.h" #include "libavutil/imgutils.h" #include "libavutil/avutil.h" }; extern "C" JNIEXPORT jstring JNICALL Java_com_szboot_helloffmpeg_MainActivity_stringFromJNI( JNIEnv *env, jobject /* this */) { std::string hello = "Hello from C++"; av_register_all(); return env->NewStringUTF(hello.c_str()); } 【坑】這樣以后進行同步和編譯,,將出現(xiàn)如下錯誤: Error:error: '../../../../src/main/jniLibs/mips64/libavcodec-57.so', needed by '../../../../build/intermediates/cmake/debug/obj/mips64/libnative-lib.so', missing and no known rule to make it 解決辦法,,見第四步 第四步:修改build.gradle文件 在andriod studio面板的Gradle Script -> build.gradle(Module:app),在defaultConfig {……}的段里面,加上這段 ndk { abiFilters 'armeabi' } 這樣就可以編譯運行了,。 |
|