iOS packaging fails with "PhysX" and "APEX" modules

Hello guys,

I’m working on project using PhysX module. But to compile project with “PhysXIncludes.h” and “PhysXSupport.h” headers in my class I also need to add “APEX” module to PublicDependencyModuleNames due to crossdependency in these two headers. This project builds successfully for Android but building for iOS fails.

Repro steps:

  1. Create new blank C++ project;
  2. Add “PhysX” and “APEX” to your PublicDependencyModuleNames array;
  3. Launch or Package for iOS.

Please see attached log:

LogPlayLevel: mono: Compiling with iPhoneOS SDK 8.4
LogPlayLevel: mono: Parsing headers for ApexFail
LogPlayLevel: mono:   
Running UnrealHeaderTool "/Projects/ApexFail/ApexFail.uproject" "/Projects/ApexFail/Intermediate/Build/IOS/ApexFail/Development/UnrealHeaderTool.manifest"
-LogCmds="loginit warning, logexit warning, logdatabase error" -rocket
-installed
LogPlayLevel: mono: Reflection code generated for ApexFail in 4.6969258 seconds
LogPlayLevel: mono: Compiling with these architectures: armv7
LogPlayLevel: mono: Performing 5 actions (8 in parallel)
LogPlayLevel: mono: [2/5] clang++ ApexFailGameMode.cpp
LogPlayLevel: mono: [3/5] clang++ ApexFail.cpp
LogPlayLevel: mono: [1/5] clang++ ApexFail.generated.cpp
LogPlayLevel: mono: [4/5] clang++ UELinkerFixups.cpp
LogPlayLevel: mono: In file included from <built-in>:353:
LogPlayLevel: mono: <command line>:67:9: error: 'WITH_APEX' macro redefined [-Werror,-Wmacro-redefined]
LogPlayLevel: mono: #define WITH_APEX 1
LogPlayLevel: mono:         ^
LogPlayLevel: mono: <command line>:66:9: note: previous definition is here
LogPlayLevel: mono: #define WITH_APEX 0 LogPlayLevel: mono:        ^
LogPlayLevel: mono: In file included from <built-in>:353:
LogPlayLevel: mono: <command line>:67:9: error: 'WITH_APEX' macro redefined [-Werror,-Wmacro-redefined]
LogPlayLevel: mono: #define WITH_APEX 1
LogPlayLevel: mono:         ^
LogPlayLevel: mono: <command line>:66:9: note: previous definition is here
LogPlayLevel: mono: #define WITH_APEX 0
LogPlayLevel: mono:        ^
LogPlayLevel: mono: In file included from <built-in>:353:
LogPlayLevel: mono: <command line>:67:9: error: 'WITH_APEX' macro redefined [-Werror,-Wmacro-redefined]
LogPlayLevel: mono: #define WITH_APEX 1
LogPlayLevel: mono:         ^
LogPlayLevel: mono: <command line>:66:9: note: previous definition is here
LogPlayLevel: mono: #define WITH_APEX 0 LogPlayLevel: mono:        ^
LogPlayLevel: mono: 1 error generated.
LogPlayLevel: mono: 1 error generated.
LogPlayLevel: mono: 1 error generated.
LogPlayLevel: mono:
-------- End Detailed Actions Stats ----------------------------------------------------------- LogPlayLevel: mono: ERROR: UBT ERROR: Failed to produce item: /Projects/ApexFail/Binaries/IOS/ApexFail
LogPlayLevel: mono: Total build time:
20.93 seconds
LogPlayLevel: CommandUtils.Run: Run: Took 20.991247s to run mono, ExitCode=5
LogPlayLevel: BuildCommand.Execute: ERROR: BUILD FAILED
LogPlayLevel: Program.Main: ERROR: AutomationTool terminated with exception:

Hello Acrossfy,

This is an expected error as APEX is not supported for mobile development by UE4 at this time. If you wish to use APEX for mobile development, you’ll need to get the APEX source from Nvidia and implement it manually.

Have a nice day!

Hello Mattew,

Thank you for your answer. But can you please explain why build for Android with the same module is successful? It looks strange for me… So I’m not using APEX directly, but when I include “PhysXIncludes.h” it requires APEX module for successful compilation. Without PhysXIncludes I can’t use some basic PhysX types which used in BodyInstance for example.

I’m also need to include PhysXSupport.h which also requires APEX module.

Try to include PhysXIncludes after these lines of code, it may be a possible workaround for doing so without APEX

#ifdef WITH_APEX
#undefine WITH_APEX
#endif
#define WITH_APEX 0

As Mattew said, APEX is not supported for mobile. It means that if you want to use only PhysX (without APEX) on iOS - you can’t cause main Physx headers like “PhysXIncludes.h” and “PhysXSupport.h” are dependent with APEX includes. It will be build for Android, but will fail on iOS. I think that it’s very strange and looks like a bug.

In my case I found workaround - I copied all required physx includes in my class with physics and I redefined all required macroses and variables. And now I can compile project and run it on iOS and Android without APEX module.

Error: fatal error C1021: invalid preprocessor command ‘undefine’

I apologize for the typo, it should be #undef, not #undefine

Hm… This answer should not be marked as correct because the main question: why it works on Android and doesn’t work on iOS? And it is still unanswered.

I didn’t realize that I never explained. Although it is working for you on Android, it isn’t suppose to and I’m not quite sure why it is. There are settings in the packaging (part of the source code) which Android and iOS should both be setting to disable building APEX.

Have you tried using any APEX features on your Android built project to see if they are working? It may be packaging but disabling it automatically and never using it.

I didn’t try to use APEX features on Android, but I guess that it works on Android exactly as you described. And due to many crossdependecies between PhysX and APEX I think that it’s the best solution. So I can package PhysX and APEX (because standard PhysX headers require it) and I will have ability to use buiit-in PhysX header files on Android without any troubles. But on iOS I can’t do it the same way. I need to make my own physX headers and redefine standard macroses and variables as I described in my answer. Only after that I can try to use some PhysX features on iOS.