1. Environment and preparation
System: macOS Mojave version 10.14.4
NDK: android-ndk-r8d
Mp4v2 Version: 2.0.0
Links to various NDK versions: https://blog.csdn.net/shuzfan/article/details/52690554
android-ndk-r8d(December 2012)Only 32-bit version, r8e Is the first 64-bit version NDK
MacOS X 32-bit : http://Dl.google.com/android/ndk/android-ndk-r8d-darwin-x86.tar.bz2 (click to download directly)
2, Steps
1. Download the source code
The full code of the Mp4v2 library, which contains multiple versions, can be downloaded synchronously using SVN. This is not suitable only for ordinary developers who want to use the Mp4v2 library. It is recommended that ordinary developers download the Release version directly. The current version is 2.0.0, which is described below.
Mp4v2 open source address (https://code.google.com/archive/p/mp4v2)
Ordinary developers who want to use Mp4v2 recommend downloading the Release version, which I compiled. Mp4v2 2.0.0<Click Download> (https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/mp4v2/mp4v2-2.0.0.tar.bz2)
2. Directory Structure Adjustment
- Unzip the downloaded compressed file mp4v2-2.0.0.tar.bz2 to get the project mp4v2-2.0.0;
- Create a new folder jni and move the source code into it, mainly the src, libplatform, libutil, mp4v2 folders, where src, libplatform and libutil are copied directly from the mp4v2-2.0.0 directory, and mp4v2 is copied from the includ under mp4v2-2.0.0;directory structure
- Create a new folder jni and move the source code into it, mainly the src, libplatform, libutil, mp4v2 folders, where src, libplatform and libutil are copied directly from the mp4v2-2.0.0 directory, and mp4v2 is copied from the includ under mp4v2-2.0.0;
-
The libs and obj directories correspond to the output and intermediate file directories of the link library, respectively
Directory where libs output libMp4v2.so files
The intermediate file directory produced by the obj compilation process, as shown in the figureobj compilation directory
-
The libs and obj directories correspond to the output and intermediate file directories of the link library, respectively
3. Create files Android.mk and Application.mk
These two files are placed in the jni directory
Contents of Android.mk file
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 file
APP_ABI := armeabi APP_PLATFORM := android-8 APP_STL := stlport_static APP_CPPFLAGS += -fno-rtti
4. Compile
- cd to jni directory
- Call NDK tool ndk-build to compile
Since I downloaded several versions of NDK here, and the environment variable specifies that the NDK version is 18, which is not suitable for compiling here, I used the $/Users/Martin/Documents/AndroidDev/android-ndk-r8d/ndk-build command, which specifies that the corresponding NDK is compiled. If the developers do not use the same NDK version, they need to modify the variable NDK=/Users/Mart in the Android.mk fileIn/Documents/AndroidDev/android-ndk-r8d, specify the corresponding NDK, but also modify the LOCAL_LDFLAGS: = \ $(NDK)/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/libc++.a to the corresponding.a file path in the NDK, as shown in Figure:
If you make the appropriate changes, you may encounter compilation problems, which are described below.
3, Result
Terminal terminal output:
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$
Project folder:
4, Questions
Problems that may arise if the NDK version is too high:
Question 1: armeabi is not supported, after R16, armeabi was discarded
Question 2: APP_STL stlport_static is no longer supported
Question 3: NDK is specified in Android.mk as android-ndk-r8d, if not used, remember to replace
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. Reference article links
Compile mp4v2 on Linux to generate So files for Android
android compiles mp4v2 2.0.0 to generate dynamic libraries