Google Play Services - How do I remove unused APIs ? Dex Methods > 64K

I’ve tried adding the Unity Google Play Services package into my project but I also have a lot of other plug-ins such as Firebase, Google Ads, Chartboost, Applovin etc and it’s caused my build to fail with the following error:

Cannot fit requested classes in a single dex file (# methods: 75537 > 65536)

I’ve tried using ProGuard to strip out the unused crap and finally got the thing to build but the logcat is full of errors about missing classes and Google Play isn’t logging in properly. It seems that I have to add ProGuard rules for each SDK that I’m using but I just can’t get this Google Play Games to login. If I strip out the Ad SDKs so I can build without ProGuard then Google Play Games logs in no problem. Does anybody know how I can remove the Google Play Services APIs that I don’t use such as Cloud Messaging, Panorama Viewer etc so I can get the dex method count below 64K again so I don’t have to use ProGuard ? Google’s Android SetUp docs state:

“Note: Don’t use the combined play-services target. It brings in dozens of libraries, bloating your application. Instead, specify only the specific Google Play services APIs your app uses.”

Google+ com.google.android.gms:play-services-plus:17.0.0
Google Account Login com.google.android.gms:play-services-auth:17.0.0
Google Actions, Base Client Library com.google.android.gms:play-services-base:17.0.0
Google Sign In com.google.android.gms:play-services-identity:17.0.0
Google Analytics com.google.android.gms:play-services-analytics:17.0.0
Google Awareness com.google.android.gms:play-services-awareness:17.0.0
Google Cast com.google.android.gms:play-services-cast:17.0.0
Google Cloud Messaging com.google.android.gms:play-services-gcm:17.0.0
Google Drive com.google.android.gms:play-services-drive:17.0.0
Google Fit com.google.android.gms:play-services-fitness:17.0.0
Google Location and Activity Recognition com.google.android.gms:play-services-location:17.0.0
Google Mobile Ads com.google.android.gms:play-services-ads:18.0.0
Mobile Vision com.google.android.gms:play-services-vision:18.0.0
Google Nearby com.google.android.gms:play-services-nearby:17.0.0
Google Panorama Viewer com.google.android.gms:play-services-panorama:17.0.0
Google Play Game services com.google.android.gms:play-services-games:18.0.0
SafetyNet com.google.android.gms:play-services-safetynet:17.0.0
Google Pay com.google.android.gms:play-services-wallet:17.0.0
Wear OS by Google com.google.android.gms:play-services-wearable:17.0.0

Include any of the above dependencies into your app build.gradle file, for example:
apply plugin: 'com.android.application'
...

dependencies {
implementation 'com.google...'
}

Is there any way to do this with a Unity post build script or something similar? I’m no expert on Android and this is driving me crazy!

have the same problem

AndroidResolverDependencies.xml will help you