UiAUtomator shut down unexpectedly

Platform you are automating - Android
Appium version - 1.7.2
Simulator/Emulator or Real Device - Real device
The language you are using for writing tests (client binding) - Java
Your OS - Mac OS Sierra 10.12.6

I have been using Appium for a long time and facing this issue for the past week.

I get this error when I am trying to invoke the Amazon app (downloaded from Play Store). This is what I am doing:

Invoke Appium server using Appium Desktop.
Trigger the Amazon app using the required capabilities.
Click on "Skip Sign-In" on first screen.

The App then abruptly closes and I get the following error log on the Appium logs:

Encountered internal error running command: Error: UiAUtomator shut down unexpectedly
at AndroidBootstrap.callee$2$0$ (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/appium-android-bootstrap/build/lib/bootstrap.js:345:56)
at tryCatch (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules /babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
at Promise.F (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
at AsyncIterator.enqueue (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
at AsyncIterator.prototype.(anonymous function) [as next] (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:    at Object.runtime.async (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
at UiAutomator.callee$2$0 (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/appium-android-bootstrap/build/lib/bootstrap.js:340:42)
at emitOne (events.js:96:13)
at UiAutomator.emit (events.js:188:7)
at UiAutomator.changeState (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/appium-uiautomator/build/lib/uiautomator.js:173:12)
at SubProcess. (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/appium-uiautomator/build/lib/uiautomator.js:95:21)
at emitTwo (events.js:106:13)
at SubProcess.emit (events.js:191:7)
at ChildProcess. (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/teen_process/build/lib/teen_process.js:289:23)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
From previous event:
at new AndroidBootstrap (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium    /node_modules/appium-android-bootstrap/build/lib/bootstrap.js:61:33)
at AndroidDriver.startAndroidSession$ (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/appium-android-driver/build/lib/driver.js:444:30)
at tryCatch (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/Users/arjunvij/Desktop/AVK/Inspectors/appium-desktop-master/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at process._tickCallback (internal/process/next_tick.js:103:7)

Things that I have done:

Restarted the laptop/phone. Works once and then I start getting this error again.
Set the DesiredCapability "automationName" to "uiautomator2". Again, works once and then the same error again.

After doing some search online, the closest error (which I think is the issue, but not sure), is that the appium nodejs garbage collector has a problem - Android UIAutomator shutdown unexpectedly

But I am not sure how to set the “max_old_space_size” value, assuming that is the problem.

Has anyone faced this issue?

NOTE: I get the same error when I invoke Appium from terminal as well.

Kindly help me fix this issue as I am blocked here.