How to Use zlib Library in Android Project

Hello,

I’m attempting to use zlib (the version that comes with Unreal Engine) to uncompress some data that comes from a server. I’ve added the following to my .Build.cs file…

AddEngineThirdPartyPrivateStaticDependencies(Target, “zlib”);

…and I’m including the following file in my code: #include “ThirdParty/zlib/zlib-1.2.5/Inc/zlib.h”

Everything works great when I run my game through the editor (which is running on Windows 10). The problem is that when I try to package the game for Android, I get some error messages that appear to be related to zlib:

PackagingResults: Error: ‘_LARGEFILE64_SOURCE’ is not defined, evaluates to 0 [-Werror,-Wundef]
PackagingResults: Error: ‘_FILE_OFFSET_BITS’ is not defined, evaluates to 0 [-Werror,-Wundef]
PackagingResults: Error: ‘_LARGEFILE64_SOURCE’ is not defined, evaluates to 0 [-Werror,-Wundef]
PackagingResults: Error: ‘_FILE_OFFSET_BITS’ is not defined, evaluates to 0 [-Werror,-Wundef]

I don’t have any clue on what to try to resolve these errors. Does anyone have any experience getting zlib to work in an Android project? Thanks in advance!

I had the same error. Maybe for somebody it might be useful, how I solved it.

I have noticed, that in zlib (zconf.h) there is comment:

/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
 * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
 * though the former does not conform to the LFS document), but considering
 * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
 * equivalently requesting no 64-bit operations
 */

So, I just add:

#define _LARGEFILE64_SOURCE

before

#include <zlib.h>

and of course after code I used:

#undef _LARGEFILE64_SOURCE

Maybe it would help, for somebody.

this only support windows

thanks