我需要为我的 Android 项目构建 FreeImage.a 库。我已经从项目页面下载了源代码。
面向 Android 时,如何从原始资源构建此项目?
要从原始资源构建适用于 Android 的FreeImage 3.15.3,您需要 3 样东西:
1) 在 FreeImage 文件夹中创建文件 jni/Application.mk:
APP_OPTIM := release
APP_PLATFORM := android-8
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -DANDROID
APP_ABI := armeabi-v7a x86
APP_MODULES := FreeImage
2)创建文件jni/Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
GLOBAL_C_INCLUDES := \
$(LOCAL_PATH)/../Source \
$(LOCAL_PATH)/../Source \
$(LOCAL_PATH)/../Source/DeprecationManager \
$(LOCAL_PATH)/../Source/FreeImage \
$(LOCAL_PATH)/../Source/FreeImageLib \
$(LOCAL_PATH)/../Source/FreeImageToolkit \
$(LOCAL_PATH)/../Source/LibJPEG \
$(LOCAL_PATH)/../Source/LibMNG \
$(LOCAL_PATH)/../Source/LibOpenJPEG \
$(LOCAL_PATH)/../Source/LibPNG \
$(LOCAL_PATH)/../Source/LibRawLite \
$(LOCAL_PATH)/../Source/LibRawLite/dcraw \
$(LOCAL_PATH)/../Source/LibRawLite/internal \
$(LOCAL_PATH)/../Source/LibRawLite/libraw \
$(LOCAL_PATH)/../Source/LibRawLite/src \
$(LOCAL_PATH)/../Source/LibTIFF \
$(LOCAL_PATH)/../Source/Metadata \
$(LOCAL_PATH)/../Source/OpenEXR \
$(LOCAL_PATH)/../Source/OpenEXR/Copyrights \
$(LOCAL_PATH)/../Source/OpenEXR/Half \
$(LOCAL_PATH)/../Source/OpenEXR/Iex \
$(LOCAL_PATH)/../Source/OpenEXR/IlmImf \
$(LOCAL_PATH)/../Source/OpenEXR/IlmThread \
$(LOCAL_PATH)/../Source/OpenEXR/Imath \
$(LOCAL_PATH)/../Source/ZLib \
LOCAL_SRC_FILES = ../Source/FreeImage/BitmapAccess.cpp ../Source/FreeImage/ColorLookup.cpp ../Source/FreeImage/FreeImage.cpp ../Source/FreeImage/FreeImageC.c ../Source/FreeImage/FreeImageIO.cpp ../Source/FreeImage/GetType.cpp ../Source/FreeImage/MemoryIO.cpp ../Source/FreeImage/PixelAccess.cpp ../Source/FreeImage/J2KHelper.cpp ../Source/FreeImage/MNGHelper.cpp ../Source/FreeImage/Plugin.cpp ../Source/FreeImage/PluginBMP.cpp ../Source/FreeImage/PluginCUT.cpp ../Source/FreeImage/PluginDDS.cpp ../Source/FreeImage/PluginEXR.cpp ../Source/FreeImage/PluginG3.cpp ../Source/FreeImage/PluginGIF.cpp ../Source/FreeImage/PluginHDR.cpp ../Source/FreeImage/PluginICO.cpp ../Source/FreeImage/PluginIFF.cpp ../Source/FreeImage/PluginJ2K.cpp ../Source/FreeImage/PluginJNG.cpp ../Source/FreeImage/PluginJP2.cpp ../Source/FreeImage/PluginJPEG.cpp ../Source/FreeImage/PluginKOALA.cpp ../Source/FreeImage/PluginMNG.cpp ../Source/FreeImage/PluginPCD.cpp ../Source/FreeImage/PluginPCX.cpp ../Source/FreeImage/PluginPFM.cpp ../Source/FreeImage/PluginPICT.cpp ../Source/FreeImage/PluginPNG.cpp ../Source/FreeImage/PluginPNM.cpp ../Source/FreeImage/PluginPSD.cpp ../Source/FreeImage/PluginRAS.cpp ../Source/FreeImage/PluginRAW.cpp ../Source/FreeImage/PluginSGI.cpp ../Source/FreeImage/PluginTARGA.cpp ../Source/FreeImage/PluginTIFF.cpp ../Source/FreeImage/PluginWBMP.cpp ../Source/FreeImage/PluginXBM.cpp ../Source/FreeImage/PluginXPM.cpp ../Source/FreeImage/PSDParser.cpp ../Source/FreeImage/TIFFLogLuv.cpp ../Source/FreeImage/Conversion.cpp ../Source/FreeImage/Conversion16_555.cpp ../Source/FreeImage/Conversion16_565.cpp ../Source/FreeImage/Conversion24.cpp ../Source/FreeImage/Conversion32.cpp ../Source/FreeImage/Conversion4.cpp ../Source/FreeImage/Conversion8.cpp ../Source/FreeImage/ConversionFloat.cpp ../Source/FreeImage/ConversionRGB16.cpp ../Source/FreeImage/ConversionRGBF.cpp ../Source/FreeImage/ConversionType.cpp ../Source/FreeImage/ConversionUINT16.cpp ../Source/FreeImage/Halftoning.cpp ../Source/FreeImage/tmoColorConvert.cpp ../Source/FreeImage/tmoDrago03.cpp ../Source/FreeImage/tmoFattal02.cpp ../Source/FreeImage/tmoReinhard05.cpp ../Source/FreeImage/ToneMapping.cpp ../Source/FreeImage/NNQuantizer.cpp ../Source/FreeImage/WuQuantizer.cpp ../Source/DeprecationManager/Deprecated.cpp ../Source/DeprecationManager/DeprecationMgr.cpp ../Source/FreeImage/CacheFile.cpp ../Source/FreeImage/MultiPage.cpp ../Source/FreeImage/ZLibInterface.cpp ../Source/Metadata/Exif.cpp ../Source/Metadata/FIRational.cpp ../Source/Metadata/FreeImageTag.cpp ../Source/Metadata/IPTC.cpp ../Source/Metadata/TagConversion.cpp ../Source/Metadata/TagLib.cpp ../Source/Metadata/XTIFF.cpp ../Source/FreeImageToolkit/Background.cpp ../Source/FreeImageToolkit/BSplineRotate.cpp ../Source/FreeImageToolkit/Channels.cpp ../Source/FreeImageToolkit/ClassicRotate.cpp ../Source/FreeImageToolkit/Colors.cpp ../Source/FreeImageToolkit/CopyPaste.cpp ../Source/FreeImageToolkit/Display.cpp ../Source/FreeImageToolkit/Flip.cpp ../Source/FreeImageToolkit/JPEGTransform.cpp ../Source/FreeImageToolkit/MultigridPoissonSolver.cpp ../Source/FreeImageToolkit/Rescale.cpp ../Source/FreeImageToolkit/Resize.cpp ../Source/LibJPEG/./jaricom.c ../Source/LibJPEG/jcapimin.c ../Source/LibJPEG/jcapistd.c ../Source/LibJPEG/./jcarith.c ../Source/LibJPEG/jccoefct.c ../Source/LibJPEG/jccolor.c ../Source/LibJPEG/jcdctmgr.c ../Source/LibJPEG/jchuff.c ../Source/LibJPEG/jcinit.c ../Source/LibJPEG/jcmainct.c ../Source/LibJPEG/jcmarker.c ../Source/LibJPEG/jcmaster.c ../Source/LibJPEG/jcomapi.c ../Source/LibJPEG/jcparam.c ../Source/LibJPEG/jcprepct.c ../Source/LibJPEG/jcsample.c ../Source/LibJPEG/jctrans.c ../Source/LibJPEG/jdapimin.c ../Source/LibJPEG/jdapistd.c ../Source/LibJPEG/./jdarith.c ../Source/LibJPEG/jdatadst.c ../Source/LibJPEG/jdatasrc.c ../Source/LibJPEG/jdcoefct.c ../Source/LibJPEG/jdcolor.c ../Source/LibJPEG/jddctmgr.c ../Source/LibJPEG/jdhuff.c ../Source/LibJPEG/jdinput.c ../Source/LibJPEG/jdmainct.c ../Source/LibJPEG/jdmarker.c ../Source/LibJPEG/jdmaster.c ../Source/LibJPEG/jdmerge.c ../Source/LibJPEG/jdpostct.c ../Source/LibJPEG/jdsample.c ../Source/LibJPEG/jdtrans.c ../Source/LibJPEG/jerror.c ../Source/LibJPEG/jfdctflt.c ../Source/LibJPEG/jfdctfst.c ../Source/LibJPEG/jfdctint.c ../Source/LibJPEG/jidctflt.c ../Source/LibJPEG/jidctfst.c ../Source/LibJPEG/jidctint.c ../Source/LibJPEG/jmemmgr.c ../Source/LibJPEG/jmemnobs.c ../Source/LibJPEG/jquant1.c ../Source/LibJPEG/jquant2.c ../Source/LibJPEG/jutils.c ../Source/LibJPEG/transupp.c ../Source/LibPNG/./png.c ../Source/LibPNG/./pngerror.c ../Source/LibPNG/./pngget.c ../Source/LibPNG/./pngmem.c ../Source/LibPNG/./pngpread.c ../Source/LibPNG/./pngread.c ../Source/LibPNG/./pngrio.c ../Source/LibPNG/./pngrtran.c ../Source/LibPNG/./pngrutil.c ../Source/LibPNG/./pngset.c ../Source/LibPNG/./pngtrans.c ../Source/LibPNG/./pngwio.c ../Source/LibPNG/./pngwrite.c ../Source/LibPNG/./pngwtran.c ../Source/LibPNG/./pngwutil.c ../Source/LibTIFF4/./tif_aux.c ../Source/LibTIFF4/./tif_close.c ../Source/LibTIFF4/./tif_codec.c ../Source/LibTIFF4/./tif_color.c ../Source/LibTIFF4/./tif_compress.c ../Source/LibTIFF4/./tif_dir.c ../Source/LibTIFF4/./tif_dirinfo.c ../Source/LibTIFF4/./tif_dirread.c ../Source/LibTIFF4/./tif_dirwrite.c ../Source/LibTIFF4/./tif_dumpmode.c ../Source/LibTIFF4/./tif_error.c ../Source/LibTIFF4/./tif_extension.c ../Source/LibTIFF4/./tif_fax3.c ../Source/LibTIFF4/./tif_fax3sm.c ../Source/LibTIFF4/./tif_flush.c ../Source/LibTIFF4/./tif_getimage.c ../Source/LibTIFF4/./tif_jpeg.c ../Source/LibTIFF4/./tif_luv.c ../Source/LibTIFF4/./tif_lzma.c ../Source/LibTIFF4/./tif_lzw.c ../Source/LibTIFF4/./tif_next.c ../Source/LibTIFF4/./tif_ojpeg.c ../Source/LibTIFF4/./tif_open.c ../Source/LibTIFF4/./tif_packbits.c ../Source/LibTIFF4/./tif_pixarlog.c ../Source/LibTIFF4/./tif_predict.c ../Source/LibTIFF4/./tif_print.c ../Source/LibTIFF4/./tif_read.c ../Source/LibTIFF4/./tif_strip.c ../Source/LibTIFF4/./tif_swab.c ../Source/LibTIFF4/./tif_thunder.c ../Source/LibTIFF4/./tif_tile.c ../Source/LibTIFF4/./tif_version.c ../Source/LibTIFF4/./tif_warning.c ../Source/LibTIFF4/./tif_write.c ../Source/LibTIFF4/./tif_zip.c ../Source/ZLib/./adler32.c ../Source/ZLib/./compress.c ../Source/ZLib/./crc32.c ../Source/ZLib/./deflate.c ../Source/ZLib/./gzclose.c ../Source/ZLib/./gzlib.c ../Source/ZLib/./gzread.c ../Source/ZLib/./gzwrite.c ../Source/ZLib/./infback.c ../Source/ZLib/./inffast.c ../Source/ZLib/./inflate.c ../Source/ZLib/./inftrees.c ../Source/ZLib/./trees.c ../Source/ZLib/./uncompr.c ../Source/ZLib/./zutil.c ../Source/LibOpenJPEG/bio.c ../Source/LibOpenJPEG/./cidx_manager.c ../Source/LibOpenJPEG/cio.c ../Source/LibOpenJPEG/dwt.c ../Source/LibOpenJPEG/event.c ../Source/LibOpenJPEG/image.c ../Source/LibOpenJPEG/j2k.c ../Source/LibOpenJPEG/j2k_lib.c ../Source/LibOpenJPEG/jp2.c ../Source/LibOpenJPEG/jpt.c ../Source/LibOpenJPEG/mct.c ../Source/LibOpenJPEG/mqc.c ../Source/LibOpenJPEG/openjpeg.c ../Source/LibOpenJPEG/./phix_manager.c ../Source/LibOpenJPEG/pi.c ../Source/LibOpenJPEG/./ppix_manager.c ../Source/LibOpenJPEG/raw.c ../Source/LibOpenJPEG/t1.c ../Source/LibOpenJPEG/t2.c ../Source/LibOpenJPEG/tcd.c ../Source/LibOpenJPEG/tgt.c ../Source/LibOpenJPEG/./thix_manager.c ../Source/LibOpenJPEG/./tpix_manager.c ../Source/OpenEXR/./IlmImf/ImfAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfB44Compressor.cpp ../Source/OpenEXR/./IlmImf/ImfBoxAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfChannelList.cpp ../Source/OpenEXR/./IlmImf/ImfChannelListAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfChromaticities.cpp ../Source/OpenEXR/./IlmImf/ImfChromaticitiesAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfCompressionAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfCompressor.cpp ../Source/OpenEXR/./IlmImf/ImfConvert.cpp ../Source/OpenEXR/./IlmImf/ImfCRgbaFile.cpp ../Source/OpenEXR/./IlmImf/ImfDoubleAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfEnvmap.cpp ../Source/OpenEXR/./IlmImf/ImfEnvmapAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfFloatAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfFrameBuffer.cpp ../Source/OpenEXR/./IlmImf/ImfFramesPerSecond.cpp ../Source/OpenEXR/./IlmImf/ImfHeader.cpp ../Source/OpenEXR/./IlmImf/ImfHuf.cpp ../Source/OpenEXR/./IlmImf/ImfInputFile.cpp ../Source/OpenEXR/./IlmImf/ImfIntAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfIO.cpp ../Source/OpenEXR/./IlmImf/ImfKeyCode.cpp ../Source/OpenEXR/./IlmImf/ImfKeyCodeAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfLineOrderAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfLut.cpp ../Source/OpenEXR/./IlmImf/ImfMatrixAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfMisc.cpp ../Source/OpenEXR/./IlmImf/ImfOpaqueAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfOutputFile.cpp ../Source/OpenEXR/./IlmImf/ImfPizCompressor.cpp ../Source/OpenEXR/./IlmImf/ImfPreviewImage.cpp ../Source/OpenEXR/./IlmImf/ImfPreviewImageAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfPxr24Compressor.cpp ../Source/OpenEXR/./IlmImf/ImfRational.cpp ../Source/OpenEXR/./IlmImf/ImfRationalAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfRgbaFile.cpp ../Source/OpenEXR/./IlmImf/ImfRgbaYca.cpp ../Source/OpenEXR/./IlmImf/ImfRleCompressor.cpp ../Source/OpenEXR/./IlmImf/ImfScanLineInputFile.cpp ../Source/OpenEXR/./IlmImf/ImfStandardAttributes.cpp ../Source/OpenEXR/./IlmImf/ImfStdIO.cpp ../Source/OpenEXR/./IlmImf/ImfStringAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfStringVectorAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfTestFile.cpp ../Source/OpenEXR/./IlmImf/ImfThreading.cpp ../Source/OpenEXR/./IlmImf/ImfTileDescriptionAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfTiledInputFile.cpp ../Source/OpenEXR/./IlmImf/ImfTiledMisc.cpp ../Source/OpenEXR/./IlmImf/ImfTiledOutputFile.cpp ../Source/OpenEXR/./IlmImf/ImfTiledRgbaFile.cpp ../Source/OpenEXR/./IlmImf/ImfTileOffsets.cpp ../Source/OpenEXR/./IlmImf/ImfTimeCode.cpp ../Source/OpenEXR/./IlmImf/ImfTimeCodeAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfVecAttribute.cpp ../Source/OpenEXR/./IlmImf/ImfVersion.cpp ../Source/OpenEXR/./IlmImf/ImfWav.cpp ../Source/OpenEXR/./IlmImf/ImfZipCompressor.cpp ../Source/OpenEXR/./Imath/ImathBox.cpp ../Source/OpenEXR/./Imath/ImathColorAlgo.cpp ../Source/OpenEXR/./Imath/ImathFun.cpp ../Source/OpenEXR/./Imath/ImathMatrixAlgo.cpp ../Source/OpenEXR/./Imath/ImathRandom.cpp ../Source/OpenEXR/./Imath/ImathShear.cpp ../Source/OpenEXR/./Imath/ImathVec.cpp ../Source/OpenEXR/./Iex/IexBaseExc.cpp ../Source/OpenEXR/./Iex/IexThrowErrnoExc.cpp ../Source/OpenEXR/./Half/half.cpp ../Source/OpenEXR/./IlmThread/IlmThread.cpp ../Source/OpenEXR/./IlmThread/IlmThreadMutex.cpp ../Source/OpenEXR/./IlmThread/IlmThreadPool.cpp ../Source/OpenEXR/./IlmThread/IlmThreadSemaphore.cpp ../Source/LibRawLite/./internal/dcraw_common.cpp ../Source/LibRawLite/./internal/dcraw_fileio.cpp ../Source/LibRawLite/./internal/demosaic_packs.cpp ../Source/LibRawLite/./src/libraw_c_api.cpp ../Source/LibRawLite/./src/libraw_cxx.cpp ../Source/LibRawLite/./src/libraw_datastream.cpp
LOCAL_MODULE := FreeImage
GLOBAL_CFLAGS := -O3 -DHAVE_CONFIG_H=1 -DFREEIMAGE_LIB -isystem $(SYSROOT)/usr/include/
ifeq ($(TARGET_ARCH),x86)
LOCAL_CFLAGS := $(GLOBAL_CFLAGS)
else
LOCAL_CFLAGS := -mfpu=vfp -mfloat-abi=softfp -fno-short-enums $(GLOBAL_CFLAGS)
endif
LOCAL_C_INCLUDES := $(GLOBAL_C_INCLUDES)
include $(BUILD_STATIC_LIBRARY)
3)提供Android的libc中缺少的一些功能:
/// C-runtime patch
extern "C"
{
// used deep inside FreeImage
void* lfind( const void * key, const void * base, size_t num, size_t width, int (*fncomparison)(const void *, const void * ) )
{
char* Ptr = (char*)base;
for ( size_t i = 0; i != num; i++, Ptr+=width )
{
if ( fncomparison( key, Ptr ) == 0 ) return Ptr;
}
return NULL;
}
// used in libcompress
int fseeko64(FILE *stream, off64_t offset, int whence)
{
return fseek( stream, int( offset & 0xFFFFFFFF ), whence );
}
// used in libcompress
off64_t ftello64(FILE *stream)
{
return ftell( stream );
}
} // extern C
现在你可以运行ndk-build
编译你的 FreeImage。
PS Precompiled Android 版本可从Linderdaum 引擎 SDK 中的http://www.linderdaum.com获得。