Apr 29, 2019 更新锯茄,添加深入學(xué)習(xí)鏈接:Mac上使用Android Studio封裝mp4v2庫的Java Native接口
下一篇:2019-04-25 Mac上使用Android Studio封裝mp4v2庫的Java Native接口(http://www.reibang.com/p/5d9ab4ee51d4)
1,環(huán)境及準(zhǔn)備
系統(tǒng):macOS Mojave version 10.14.4
NDK: android-ndk-r8d
Mp4v2版本:2.0.0
NDK各個(gè)版本鏈接:https://blog.csdn.net/shuzfan/article/details/52690554
android-ndk-r8d(December 2012)只有32位版本,r8e是第1個(gè)有64位版本的NDK
MacOS X 32-bit : http://dl.google.com/android/ndk/android-ndk-r8d-darwin-x86.tar.bz2(點(diǎn)擊直接下載)
2肌幽,步驟
1. 下載源碼
Mp4v2庫全部代碼晚碾,包含多個(gè)版本,可以使用SVN進(jìn)行同步下載喂急,這個(gè)不適合只是使用想要使用Mp4v2庫的普通開發(fā)開發(fā)者格嘁,官方推薦普通開發(fā)者直接下載Release版比較好,目前版本是2.0.0廊移,下文有介紹糕簿。
Mp4v2開源代碼地址(https://code.google.com/archive/p/mp4v2)
普通開發(fā)者想要使用Mp4v2的話,推薦還是下載Release版就好了狡孔,我編譯的也是這個(gè)版本懂诗,Mp4v2 2.0.0<點(diǎn)擊下載>(https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/mp4v2/mp4v2-2.0.0.tar.bz2)
2. 目錄結(jié)構(gòu)調(diào)整
- 解壓下載好的壓縮文件 mp4v2-2.0.0.tar.bz2 得到項(xiàng)目 mp4v2-2.0.0 ;
- 新建文件夾 jni 并把源碼移入苗膝,主要是 src殃恒、libplatform、libutil辱揭、mp4v2 文件夾离唐,其中 src、libplatform 和 libutil 直接從 mp4v2-2.0.0 目錄下拷貝问窃,mp4v2 從 mp4v2-2.0.0 下的 include 中拷貝侯繁;
- 新建文件夾 jni 并把源碼移入苗膝,主要是 src殃恒、libplatform、libutil辱揭、mp4v2 文件夾离唐,其中 src、libplatform 和 libutil 直接從 mp4v2-2.0.0 目錄下拷貝问窃,mp4v2 從 mp4v2-2.0.0 下的 include 中拷貝侯繁;
-
libs 和 obj 目錄分別對(duì)應(yīng)鏈接庫的輸出目錄和中間文件目錄
· libs 輸出libMp4v2.so文件的目錄
· obj 編譯過程產(chǎn)生的中間文件目錄,如圖
-
libs 和 obj 目錄分別對(duì)應(yīng)鏈接庫的輸出目錄和中間文件目錄
3. 創(chuàng)建文件Android.mk和Application.mk文件
這兩個(gè)文件放在 jni 目錄下
Android.mk文件內(nèi)容
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
NDK=/Users/Martin/Documents/AndroidDev/android-ndk-r8d
LOCAL_SRC_FILES:= \
src/3gp.cpp src/atom_ac3.cpp \
src/atom_amr.cpp src/atom_avc1.cpp src/atom_avcC.cpp \
src/atom_chpl.cpp src/atom_colr.cpp src/atom_d263.cpp \
src/atom_dac3.cpp src/atom_damr.cpp src/atom_dref.cpp \
src/atom_elst.cpp src/atom_enca.cpp src/atom_encv.cpp \
src/atom_free.cpp src/atom_ftyp.cpp src/atom_ftab.cpp \
src/atom_gmin.cpp src/atom_hdlr.cpp src/atom_hinf.cpp \
src/atom_hnti.cpp src/atom_href.cpp src/atom_mdat.cpp \
src/atom_mdhd.cpp src/atom_meta.cpp src/atom_mp4s.cpp \
src/atom_mp4v.cpp src/atom_mvhd.cpp src/atom_nmhd.cpp \
src/atom_ohdr.cpp src/atom_pasp.cpp src/atom_root.cpp \
src/atom_rtp.cpp src/atom_s263.cpp src/atom_sdp.cpp \
src/atom_sdtp.cpp src/atom_smi.cpp src/atom_sound.cpp \
src/atom_standard.cpp src/atom_stbl.cpp src/atom_stdp.cpp \
src/atom_stsc.cpp src/atom_stsd.cpp src/atom_stsz.cpp \
src/atom_stz2.cpp src/atom_text.cpp src/atom_tfhd.cpp \
src/atom_tkhd.cpp src/atom_treftype.cpp src/atom_trun.cpp \
src/atom_tx3g.cpp src/atom_udta.cpp src/atom_url.cpp \
src/atom_urn.cpp src/atom_uuid.cpp src/atom_video.cpp \
src/atom_vmhd.cpp src/atoms.h src/cmeta.cpp \
src/descriptors.cpp src/descriptors.h src/exception.cpp \
src/exception.h src/enum.h src/enum.tcc src/impl.h \
src/isma.cpp src/log.h src/log.cpp src/mp4.cpp src/mp4array.h \
src/mp4atom.cpp src/mp4atom.h src/mp4container.cpp \
src/mp4container.h src/mp4descriptor.cpp src/mp4descriptor.h \
src/mp4file.cpp src/mp4file.h src/mp4file_io.cpp \
src/mp4info.cpp src/mp4property.cpp src/mp4property.h \
src/mp4track.cpp src/mp4track.h src/mp4util.cpp src/mp4util.h \
src/ocidescriptors.cpp src/ocidescriptors.h src/odcommands.cpp \
src/odcommands.h src/qosqualifiers.cpp src/qosqualifiers.h \
src/rtphint.cpp src/rtphint.h src/src.h src/text.cpp \
src/text.h src/util.h src/bmff/bmff.h src/bmff/impl.h \
src/bmff/typebmff.cpp src/bmff/typebmff.h \
src/itmf/CoverArtBox.cpp src/itmf/CoverArtBox.h \
src/itmf/Tags.cpp src/itmf/Tags.h src/itmf/generic.cpp \
src/itmf/generic.h src/itmf/impl.h src/itmf/itmf.h \
src/itmf/type.cpp src/itmf/type.h \
src/qtff/ColorParameterBox.cpp src/qtff/ColorParameterBox.h \
src/qtff/PictureAspectRatioBox.cpp \
src/qtff/PictureAspectRatioBox.h src/qtff/coding.cpp \
src/qtff/coding.h src/qtff/impl.h src/qtff/qtff.h \
libplatform/endian.h libplatform/impl.h \
libplatform/io/File.cpp libplatform/io/File.h \
libplatform/io/FileSystem.cpp libplatform/io/FileSystem.h \
libplatform/number/random.h libplatform/platform.h \
libplatform/platform_base.h libplatform/platform_posix.h \
libplatform/process/process.h \
libplatform/prog/option.cpp libplatform/prog/option.h \
libplatform/sys/error.cpp libplatform/sys/error.h \
libplatform/time/time.cpp libplatform/time/time.h \
libplatform/warning.h libplatform/io/File_posix.cpp \
libplatform/io/FileSystem_posix.cpp \
libplatform/number/random_posix.cpp \
libplatform/process/process_posix.cpp \
libplatform/time/time_posix.cpp \
libutil/Database.cpp \
libutil/Database.h libutil/Timecode.cpp libutil/Timecode.h \
libutil/TrackModifier.cpp libutil/TrackModifier.h \
libutil/Utility.cpp libutil/Utility.h libutil/crc.cpp \
libutil/crc.h libutil/impl.h libutil/other.cpp libutil/other.h \
libutil/util.h
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := -fexceptions
LOCAL_LDFLAGS := \
$(NDK)/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/libsupc++.a
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := \
libutils \
libbinder \
libcutils
LOCAL_CXXFLAGS :=-fexceptions -Wno-write-strings
LOCAL_MODULE:= libMp4v2
LOCAL_CPPFLAGS := -O2 -fexceptions -DHAVE_SOCKLEN_T -DHAVE_STRUCT_IOVEC
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
Application.mk文件
APP_ABI := armeabi
APP_PLATFORM := android-8
APP_STL := stlport_static
APP_CPPFLAGS += -fno-rtti
4.編譯
-
cd
到jni
目錄
-
- 調(diào)用NDK工具ndk-build進(jìn)行編譯
因?yàn)槲疫@邊下載了多個(gè)版本的NDK泡躯,環(huán)境變量指定NDK版本是18贮竟,不適合在這里進(jìn)行編譯,所以我這邊使用了 $ /Users/Martin/Documents/AndroidDev/android-ndk-r8d/ndk-build
命令较剃,指定了對(duì)應(yīng)的NDK進(jìn)行編譯咕别,開發(fā)者如果不使用同樣的NDK版本,則需要修改Android.mk
文件中的變量NDK=/Users/Martin/Documents/AndroidDev/android-ndk-r8d
写穴,指定對(duì)應(yīng)NDK惰拱,同時(shí)也要修改LOCAL_LDFLAGS := \ $(NDK)/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/libsupc++.a
到NDK中對(duì)應(yīng)的.a
文件路徑,如圖:
如果做相應(yīng)修改啊送,則可能會(huì)遇到編譯問題偿短,下文有介紹。
3馋没,結(jié)果
Terminal
終端輸出結(jié)果:
MartinMac:jni Martin$ /Users/Martin/Documents/AndroidDev/android-ndk-r8d/ndk-build
Android NDK: WARNING: Unsupported source file extensions in /Users/Martin/GitHub/Mp4v2/mp4v2-2.0.0/jni/Android.mk for module Mp4v2
Android NDK: src/atoms.h src/descriptors.h src/exception.h src/enum.h src/enum.tcc src/impl.h src/log.h src/mp4array.h src/mp4atom.h src/mp4container.h src/mp4descriptor.h src/mp4file.h src/mp4property.h src/mp4track.h src/mp4util.h src/ocidescriptors.h src/odcommands.h src/qosqualifiers.h src/rtphint.h src/src.h src/text.h src/util.h src/bmff/bmff.h src/bmff/impl.h src/bmff/typebmff.h src/itmf/CoverArtBox.h src/itmf/Tags.h src/itmf/generic.h src/itmf/impl.h src/itmf/itmf.h src/itmf/type.h src/qtff/ColorParameterBox.h src/qtff/PictureAspectRatioBox.h src/qtff/coding.h src/qtff/impl.h src/qtff/qtff.h libplatform/endian.h libplatform/impl.h libplatform/io/File.h libplatform/io/FileSystem.h libplatform/number/random.h libplatform/platform.h libplatform/platform_base.h libplatform/platform_posix.h libplatform/process/process.h libplatform/prog/option.h libplatform/sys/error.h libplatform/time/time.h libplatform/warning.h libutil/Database.h libutil/Timecode.h libutil/TrackModifier.h libutil/Utility.h libutil/crc.h libutil/impl.h libutil/other.h libutil/util.h
Compile++ arm : Mp4v2 <= 3gp.cpp
Compile++ arm : Mp4v2 <= atom_ac3.cpp
Compile++ arm : Mp4v2 <= atom_amr.cpp
Compile++ arm : Mp4v2 <= atom_avc1.cpp
Compile++ arm : Mp4v2 <= atom_avcC.cpp
Compile++ arm : Mp4v2 <= atom_chpl.cpp
Compile++ arm : Mp4v2 <= atom_colr.cpp
Compile++ arm : Mp4v2 <= atom_d263.cpp
Compile++ arm : Mp4v2 <= atom_dac3.cpp
Compile++ arm : Mp4v2 <= atom_damr.cpp
Compile++ arm : Mp4v2 <= atom_dref.cpp
Compile++ arm : Mp4v2 <= atom_elst.cpp
Compile++ arm : Mp4v2 <= atom_enca.cpp
Compile++ arm : Mp4v2 <= atom_encv.cpp
Compile++ arm : Mp4v2 <= atom_free.cpp
Compile++ arm : Mp4v2 <= atom_ftyp.cpp
Compile++ arm : Mp4v2 <= atom_ftab.cpp
Compile++ arm : Mp4v2 <= atom_gmin.cpp
Compile++ arm : Mp4v2 <= atom_hdlr.cpp
Compile++ arm : Mp4v2 <= atom_hinf.cpp
Compile++ arm : Mp4v2 <= atom_hnti.cpp
Compile++ arm : Mp4v2 <= atom_href.cpp
Compile++ arm : Mp4v2 <= atom_mdat.cpp
Compile++ arm : Mp4v2 <= atom_mdhd.cpp
Compile++ arm : Mp4v2 <= atom_meta.cpp
Compile++ arm : Mp4v2 <= atom_mp4s.cpp
Compile++ arm : Mp4v2 <= atom_mp4v.cpp
Compile++ arm : Mp4v2 <= atom_mvhd.cpp
Compile++ arm : Mp4v2 <= atom_nmhd.cpp
Compile++ arm : Mp4v2 <= atom_ohdr.cpp
Compile++ arm : Mp4v2 <= atom_pasp.cpp
Compile++ arm : Mp4v2 <= atom_root.cpp
Compile++ arm : Mp4v2 <= atom_rtp.cpp
Compile++ arm : Mp4v2 <= atom_s263.cpp
Compile++ arm : Mp4v2 <= atom_sdp.cpp
Compile++ arm : Mp4v2 <= atom_sdtp.cpp
Compile++ arm : Mp4v2 <= atom_smi.cpp
Compile++ arm : Mp4v2 <= atom_sound.cpp
Compile++ arm : Mp4v2 <= atom_standard.cpp
Compile++ arm : Mp4v2 <= atom_stbl.cpp
Compile++ arm : Mp4v2 <= atom_stdp.cpp
Compile++ arm : Mp4v2 <= atom_stsc.cpp
Compile++ arm : Mp4v2 <= atom_stsd.cpp
Compile++ arm : Mp4v2 <= atom_stsz.cpp
Compile++ arm : Mp4v2 <= atom_stz2.cpp
Compile++ arm : Mp4v2 <= atom_text.cpp
Compile++ arm : Mp4v2 <= atom_tfhd.cpp
Compile++ arm : Mp4v2 <= atom_tkhd.cpp
Compile++ arm : Mp4v2 <= atom_treftype.cpp
Compile++ arm : Mp4v2 <= atom_trun.cpp
Compile++ arm : Mp4v2 <= atom_tx3g.cpp
Compile++ arm : Mp4v2 <= atom_udta.cpp
Compile++ arm : Mp4v2 <= atom_url.cpp
Compile++ arm : Mp4v2 <= atom_urn.cpp
Compile++ arm : Mp4v2 <= atom_uuid.cpp
Compile++ arm : Mp4v2 <= atom_video.cpp
Compile++ arm : Mp4v2 <= atom_vmhd.cpp
Compile++ arm : Mp4v2 <= cmeta.cpp
Compile++ arm : Mp4v2 <= descriptors.cpp
Compile++ arm : Mp4v2 <= exception.cpp
Compile++ arm : Mp4v2 <= isma.cpp
Compile++ arm : Mp4v2 <= log.cpp
Compile++ arm : Mp4v2 <= mp4.cpp
Compile++ arm : Mp4v2 <= mp4atom.cpp
Compile++ arm : Mp4v2 <= mp4container.cpp
Compile++ arm : Mp4v2 <= mp4descriptor.cpp
Compile++ arm : Mp4v2 <= mp4file.cpp
Compile++ arm : Mp4v2 <= mp4file_io.cpp
Compile++ arm : Mp4v2 <= mp4info.cpp
Compile++ arm : Mp4v2 <= mp4property.cpp
Compile++ arm : Mp4v2 <= mp4track.cpp
Compile++ arm : Mp4v2 <= mp4util.cpp
Compile++ arm : Mp4v2 <= ocidescriptors.cpp
Compile++ arm : Mp4v2 <= odcommands.cpp
Compile++ arm : Mp4v2 <= qosqualifiers.cpp
Compile++ arm : Mp4v2 <= rtphint.cpp
Compile++ arm : Mp4v2 <= text.cpp
Compile++ arm : Mp4v2 <= typebmff.cpp
Compile++ arm : Mp4v2 <= CoverArtBox.cpp
Compile++ arm : Mp4v2 <= Tags.cpp
Compile++ arm : Mp4v2 <= generic.cpp
Compile++ arm : Mp4v2 <= type.cpp
Compile++ arm : Mp4v2 <= ColorParameterBox.cpp
Compile++ arm : Mp4v2 <= PictureAspectRatioBox.cpp
Compile++ arm : Mp4v2 <= coding.cpp
Compile++ arm : Mp4v2 <= File.cpp
Compile++ arm : Mp4v2 <= FileSystem.cpp
Compile++ arm : Mp4v2 <= option.cpp
Compile++ arm : Mp4v2 <= error.cpp
Compile++ arm : Mp4v2 <= time.cpp
Compile++ arm : Mp4v2 <= File_posix.cpp
Compile++ arm : Mp4v2 <= FileSystem_posix.cpp
Compile++ arm : Mp4v2 <= random_posix.cpp
Compile++ arm : Mp4v2 <= process_posix.cpp
Compile++ arm : Mp4v2 <= time_posix.cpp
Compile++ arm : Mp4v2 <= Database.cpp
Compile++ arm : Mp4v2 <= Timecode.cpp
Compile++ arm : Mp4v2 <= TrackModifier.cpp
Compile++ arm : Mp4v2 <= Utility.cpp
Compile++ arm : Mp4v2 <= crc.cpp
Compile++ arm : Mp4v2 <= other.cpp
Prebuilt : libstlport_static.a <= <NDK>/sources/cxx-stl/stlport/libs/armeabi/
SharedLibrary : libMp4v2.so
Install : libMp4v2.so => libs/armeabi/libMp4v2.so
MartinMac:jni Martin$
項(xiàng)目文件夾:
4昔逗,問題
NDK版本過高可能引起的問題:
問題1:armeabi不支持,R16后篷朵,拋棄了armeabi
問題2:APP_STL stlport_static is no longer supported
問題3:Android.mk中指定了NDK為android-ndk-r8d勾怒,如不使用婆排,切記要替換
arm-linux-androideabi-g++: error: /opt/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/libsupc++.a: No such file or directory
5,參考文章鏈接
Linux系統(tǒng)下編譯mp4v2生成Android下使用的So文件
android 編譯mp4v2 2.0.0生成動(dòng)態(tài)庫