Sometimes you only need to eliminate the warnings and your error will be disappeared automatically. Please see below special case:
I had below listed two dependencies in my module-level build.gradle file:
And the Studio had warned me as below (in addition to dex merging problem):
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.0.2, 21.0.3. Examples include com.android.support:animated-vector-drawable:27.0.2 and com.android.support:support-v4:21.0.3
So I explicitly determined a version of com.android.support:support-v4 and my both the problems (the warning and a one which was related to dex merging) solved:
implementation 'com.android.support:support-v4:27.0.2' // Just added this line (according to above warning message)
And it fixed my issues.
I also had a same problem when I tried to update from com.google.android.gms:play-services:11.2.2 to com.google.android.gms:play-services:11.4.0. Below method solved it for me: