"''#pragma optimize' is not supported" Error when building Sample Project into Android

I’m currently trying to build the Lumberyard Sample Project into Android. To do this I’m using the tutorial: https://docs.aws.amazon.com/lumberyard/latest/userguide/android-game-building.html#android-game-building-clang.

Using the clang commands for debug/profile/release are all failing in the android build tutorial using clang for the same reason:

        [ 932/2733] cxx (android_armv7_clang|debug): Code\CryEngine\CryPhysics\physicalplaceholder.cpp -> BinTemp\android_armv7_clang_debug\Code\CryEngine\CryPhysics\physicalplaceholder.cpp.7210490.o
c:\Amazon\Lumberyard\1.16.0.0\dev\Code\CryEngine\CryPhysics\livingentity.cpp:3333:9: error: '#pragma optimize' is not supported [-Werror,-Wignored-pragma-optimize]
#pragma optimize("", off)
^
1 error generated.
Build failed
<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
Compilation failed - File: 'livingentity.cpp.7210490.o', Module: 'CryPhysics', Configuration: 'android_armv7_clang|debug', error code 1
Input Files: 'c:\Amazon\Lumberyard\1.16.0.0\dev\Code\CryEngine\CryPhysics\livingentity.cpp'
Output Files: 'c:\Amazon\Lumberyard\1.16.0.0\dev\BinTemp\android_armv7_clang_debug\Code\CryEngine\CryPhysics\livingentity.cpp.7210490.o'
Command: 'C:/Users/bkvch/Downloads/android-ndk-r18b-windows-x86_64/android-ndk-r18b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --gcc-toolchain=C:/Users/bkvch/Downloads/android-ndk-r18b-windows-x86_64/android-ndk-r18b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64 --target=thumbv7-none-linux-androideabi -gdwarf-2 --sysroot=C:/Users/bkvch/Downloads/android-ndk-r18b-windows-x86_64/android-ndk-r18b\sysroot -mfloat-abi=softfp -mfpu=neon -isystem C:/Users/bkvch/Downloads/android-ndk-r18b-windows-x86_64/android-ndk-r18b\sysroot\usr\include\arm-linux-androideabi -Wall -Werror -Wno-unknown-warning-option -Wno-#pragma-messages -Wno-absolute-value -Wno-dynamic-class-memaccess -Wno-format-security -Wno-inconsistent-missing-override -Wno-invalid-offsetof -Wno-multichar -Wno-parentheses -Wno-reorder -Wno-self-assign -Wno-switch -Wno-tautological-compare -Wno-undefined-var-template -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-private-field -Wno-unused-value -Wno-unused-variable -Wno-non-pod-varargs -Wno-unused-lambda-capture -ffast-math -fvisibility=hidden -fvisibility-inlines-hidden -std=c++1y -fno-rtti -fno-exceptions -O0 -g -fno-inline -fstack-protector -femulated-tls -Wno-unused-lambda-capture -Wno-nonportable-include-path -fms-extensions -H -Wno-shift-negative-value -Wno-shadow -fpic -includec:\Amazon\Lumberyard\1.16.0.0\dev\BinTemp\android_armv7_clang_debug\Code\CryEngine\CryPhysics\StdAfx.7210490.h -Ic:\Amazon\Lumberyard\1.16.0.0\dev\BinTemp\android_armv7_clang_debug\Code\CryEngine\CryPhysics -Ic:\Amazon\Lumberyard\1.16.0.0\dev\Code\CryEngine\CryPhysics -IC:\Amazon\Lumberyard\1.16.0.0\3rdParty\boost\1.61.0-az.2 -Ic:\Amazon\Lumberyard\1.16.0.0\dev\Code\CryEngine\CryCommon -Ic:\Amazon\Lumberyard\1.16.0.0\dev\BinTemp\android_armv7_clang_debug\Code\Framework\AzCore -Ic:\Amazon\Lumberyard\1.16.0.0\dev\Code\Framework\AzCore -IC:\Users\bkvch\Downloads\android-ndk-r18b-windows-x86_64\android-ndk-r18b\sysroot\usr\include -IC:\Users\bkvch\Downloads\android-ndk-r18b-windows-x86_64\android-ndk-r18b\sources\cxx-stl\llvm-libc++\include -IC:\Users\bkvch\Downloads\android-ndk-r18b-windows-x86_64\android-ndk-r18b\sources\android\support\include -IC:\Amazon\Lumberyard\1.16.0.0\3rdParty\rapidjson\rapidjson-1.0.2.1\include -IC:\Amazon\Lumberyard\1.16.0.0\3rdParty\rapidxml\1.13-modified.1\include -IC:\Amazon\Lumberyard\1.16.0.0\3rdParty\Lua\5.1.1.8-az -IC:\Amazon\Lumberyard\1.16.0.0\3rdParty\zlib\1.2.8-pkg.2\include -DCODE_BASE_FOLDER="c:/Amazon/Lumberyard/1.16.0.0/dev/Code/" -D_DEBUG -D_LINUX -DLINUX -DANDROID -DMOBILE -D_HAS_C9X -DENABLE_TYPE_INFO -DNDK_REV_MAJOR=18 -DNDK_REV_MINOR=1 -D__ANDROID_API__=24 -DLINUX32 -D__ARM_NEON__ -DEXE_VERSION_INFO_0=1 -DEXE_VERSION_INFO_1=16 -DEXE_VERSION_INFO_2=0 -DEXE_VERSION_INFO_3=0 -DENGINE_EXPORTS -DUSE_CRY_NEW_AND_DELETE -DBINFOLDER_NAME="BinAndroidArmv7Clang.Debug" -DPLATFORM_SUPPORTS_AWS_NATIVE_SDK -DLY_BUILD=754138 -D_MT -D_DLL -DAZ_DEBUG_BUILD -DLY_METRICS_BUILD_TIME=0 c:\Amazon\Lumberyard\1.16.0.0\dev\Code\CryEngine\CryPhysics\livingentity.cpp -c -o c:\Amazon\Lumberyard\1.16.0.0\dev\BinTemp\android_armv7_clang_debug\Code\CryEngine\CryPhysics\livingentity.cpp.7210490.o'
Output:
c:\Amazon\Lumberyard\1.16.0.0\dev\Code\CryEngine\CryPhysics\livingentity.cpp:3333:9: error: '#pragma optimize' is not supported [-Werror,-Wignored-pragma-optimize]
#pragma optimize("", off)
^
1 error generated.
<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>

Currently using: ndk-r18, jdk 1.8.0_192, android sdk 25, visual studio 2017

Ouch! Remove or comment-out that #pragma in the code. It’s not needed and causes compile errors when using certain NDKs (as you have discovered). Developers like to use optimize off which allows easier debugging in Profile mode since code won’t be optimized away, but it should be removed once done debugging. This pragma will been removed in v1.17.

Sorry for the inconvenience!