Gradle build command for Android Instrumentation Test for Release build

I’m trying to build and run Android Instrumentation Test for Release build type on command line. Since it’s release build, I’ve enabled R8 minify and using proguard for optimization.
Build of the two apks (release.apk and releaseTest.apk) are successful. But while executing on emulator/device, it throws “Class/Method/Property not defined” errors. I tried to add -keep attributes in proguard rule file for every such error, but at one point, there was a “property not defined of a certain class” error, which was not matching with any properties of the class. I’m stuck here!
I was wondering how Gradle handles this scenario since the Instrumentation Test runs successfully on Android Studio. Is there a way to know what exactly does Gradle do for building and running of Instrumentation Test?

That’s probably more a question for the Android Gradle Plugin. Gradle itself does nothing in that regard.