How Do I Fix Error When Adding GameAnalytics/Google Play Services in Java?

When I tried to add the GameAnalytics plugin to my Unity game project in java, I thought it would be a simple drop-in addition. But things went downhill the moment I also had the AdInCube plugin present in the same project. Suddenly, my Android build started failing every single time. No matter how many times I cleaned and rebuilt the project, the error persisted.

I even encountered the exact same issue before when I tried to implement Google Play Services. This made it clear that the problem wasn’t specific to just one plugin.

The Error That Stopped My Build

Here’s the actual error I was seeing:

failed for task ':transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry:
com/google/android/gms/auth/api/signin/GoogleSignInAccount.class

What I Found Out

What this means is simple: both GameAnalytics and AdInCube were trying to include the same class GoogleSignInAccount.class from the Google Play Services SDK. Gradle didn’t like that.

Gradle’s job is to compile and merge all classes into one .dex file. But when it finds duplicate class files from multiple plugins, it has no idea which one to keep, so it throws an error instead. It’s a merge conflict caused by overlapping dependencies.

How I Fix the Problem

This was the part where I had to get my hands dirty with Gradle configuration. Here’s what I did:

Avoid Duplicate Dependencies

I made sure only one plugin imports the shared dependency (Google Play Services in this case). Then, I modified the mainTemplate.gradle file to explicitly exclude the Google Play Services from one plugin (AdInCube) and include only one version manually.

('com.adincube.sdk:AdinCube-Unity-3626ebe:2.3.1@aar') {
transitive = true
exclude group: 'com.google.android.gms', module: 'play-services-auth'
exclude group: 'com.google.android.gms', module: 'play-services-base'
}

implementation 'com.google.android.gms:play-services-auth:20.2.0'

Enable AndroidX Support

I also made sure Jetifier and AndroidX were enabled:

.useAndroidX=true
android.enableJetifier=true

Clean the Unity Project Completely

Before rebuilding, I deleted the following folders in my Unity project:

  • /Library
  • /Build
  • /Temp

Then I opened Unity again and rebuilt the project from scratch. This time, the error was gone.

I Added Practice Scripts to Test Functionality

To confirm both plugins worked properly, I wrote basic test scripts in Unity.

For GameAnalytics:

UnityEngine;
using GameAnalyticsSDK;

public class AnalyticsTest : MonoBehaviour, IGameAnalyticsATTListener
{
void Start()
{
GameAnalytics.Initialize();
GameAnalytics.NewDesignEvent("test:startup");
}

public void GameAnalyticsATTListenerNotDetermined() {}
public void GameAnalyticsATTListenerRestricted() {}
public void GameAnalyticsATTListenerDenied() {}
public void GameAnalyticsATTListenerAuthorized() {}
}

For AdInCube:

AdinCube;
using UnityEngine;

public class AdTest : MonoBehaviour
{
void Start()
{
AdinCubeManager.Instance.OnInterstitialLoaded += () =>
{
Debug.Log("Interstitial Loaded!");
AdinCubeManager.Instance.ShowInterstitial();
};

AdinCubeManager.Instance.LoadInterstitial();
}
}

These basic implementations confirmed that both plugins were working without crashing or causing issues.

Final Thoughts

What I’ve learned from this experience is that plugin conflicts in Unity Android builds are more common than you’d think especially when multiple SDKs rely on Google Play Services.

Here’s what I’ll always keep in mind for future projects:

  • Don’t blindly import multiple plugins without checking for overlapping dependencies.
  • Always read the documentation of each plugin to see what they import.
  • Use Gradle’s exclude rules to avoid duplicate class entries.
  • Test and verify integration with minimal runtime scripts.

This build issue taught me a lot about dependency management and Unity Android builds. Now I feel more confident in debugging Gradle errors and I hope this helps someone else facing the same headache.

Related blog posts