美文网首页程序员Android开发
2019-04-18 Mac OS交叉编译mp4v2生成so文件

2019-04-18 Mac OS交叉编译mp4v2生成so文件

作者: HaloMartin | 来源:发表于2019-04-19 15:31 被阅读4次

    1,环境及准备

    系统:macOS Mojave version 10.14.4
    NDK: android-ndk-r8d
    Mp4v2版本:2.0.0
    NDK各个版本链接:https://blog.csdn.net/shuzfan/article/details/52690554

    android-ndk-r8d(December 2012)只有32位版本,r8e是第1个有64位版本的NDK
    MacOS X 32-bit : http://dl.google.com/android/ndk/android-ndk-r8d-darwin-x86.tar.bz2(点击直接下载)

    2,步骤

    1. 下载源码

    Mp4v2库全部代码,包含多个版本,可以使用SVN进行同步下载,这个不适合只是使用想要使用Mp4v2库的普通开发开发者,官方推荐普通开发者直接下载Release版比较好,目前版本是2.0.0,下文有介绍。
    Mp4v2开源代码地址(https://code.google.com/archive/p/mp4v2)

    Mp4v2完整代码(适合研究Mp4v2库的)

    普通开发者想要使用Mp4v2的话,推荐还是下载Release版就好了,我编译的也是这个版本,Mp4v2 2.0.0<点击下载>(https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/mp4v2/mp4v2-2.0.0.tar.bz2)

    Mp4v2 2.0.0(推荐)

    2. 目录结构调整

      1. 解压下载好的压缩文件 mp4v2-2.0.0.tar.bz2 得到项目 mp4v2-2.0.0
      1. 新建文件夹 jni 并把源码移入,主要是 srclibplatformlibutilmp4v2 文件夹,其中 srclibplatformlibutil 直接从 mp4v2-2.0.0 目录下拷贝,mp4v2mp4v2-2.0.0 下的 include 中拷贝;
        目录结构
      1. libsobj 目录分别对应链接库的输出目录和中间文件目录
        · libs 输出libMp4v2.so文件的目录
        · obj 编译过程产生的中间文件目录,如图
        obj编译目录

    3. 创建文件Android.mk和Application.mk文件

    这两个文件放在 jni 目录下
    Android.mk文件内容

    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.编译

      1. cdjni 目录
      1. 调用NDK工具ndk-build进行编译

    因为我这边下载了多个版本的NDK,环境变量指定NDK版本是18,不适合在这里进行编译,所以我这边使用了 $ /Users/Martin/Documents/AndroidDev/android-ndk-r8d/ndk-build 命令,指定了对应的NDK进行编译,开发者如果不使用同样的NDK版本,则需要修改Android.mk文件中的变量NDK=/Users/Martin/Documents/AndroidDev/android-ndk-r8d,指定对应NDK,同时也要修改LOCAL_LDFLAGS := \ $(NDK)/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/libsupc++.a到NDK中对应的.a文件路径,如图:

    Android.mk中的NDK变量
    Android.mk中的LOCAL_LDFLAGS
    如果做相应修改,则可能会遇到编译问题,下文有介绍。

    3,结果

    Terminal终端输出结果:

    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$ 
    

    项目文件夹:


    输出so文件目录

    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
    

    问题4:# WARNING: …/Android.mk: non-system libraries in linker flags(https://stackoverflow.com/questions/25663989/warning-android-mk-non-system-libraries-in-linker-flags)

    5,参考文章链接

    Linux系统下编译mp4v2生成Android下使用的So文件
    android 编译mp4v2 2.0.0生成动态库

    Mac环境下配置NDK环境

    相关文章

      网友评论

        本文标题:2019-04-18 Mac OS交叉编译mp4v2生成so文件

        本文链接:https://www.haomeiwen.com/subject/nsbxgqtx.html