I had been struggling with a Google Play Store -504 error when trying to install larger apps on my Galaxy S7. Here's how I fixed it:
In Settings -> Applications -> All -> Google Play Store, Clear Cache and Data
Then, again in All Applications, Clear Cache for Google Services Framework