playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.45k stars 961 forks source link

Error Unity AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.PlayGames #3269

Open EdgarGomez opened 11 months ago

EdgarGomez commented 11 months ago

Describe the bug I've installed latest version of the plugin 0.11.01 and I´m getting this error when executing, once build, the login: Error Unity AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.PlayGames

I'm getting the error by connecting my phone and using Android Logcat. Actually the full error is:

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.PlayGames java.lang.ClassNotFoundException: com.google.android.gms.games.PlayGames at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:454) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.access$500(Unknown Source:0) at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:126) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) Caused by: java.lang.ClassNotFoundException: com.google.android.gms.games.PlayGames ... 9 more at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0 2

The code I'm using for now is this:

`using UnityEngine; using GooglePlayGames; using GooglePlayGames.BasicApi;

public class GooglePlayServicesManager : MonoBehaviour { public static GooglePlayServicesManager Instance { get; private set; } public bool isConnectedToGPS = false; private SignInStatus status;

private string leaderBoardId = "xxxxxx";

private void Awake()
{
    if (Instance == null)
    {
        Instance = this;
        DontDestroyOnLoad(gameObject);

        // Initialize Google Play Services here if needed

        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
    }
    else
    {
        Destroy(gameObject);
    }
}

public void Start()
{
    PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
}

public void LogIn()
{
    PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
}

internal void ProcessAuthentication(SignInStatus status)
{
    if (status == SignInStatus.Success)
    {
        // Continue with Play Games Services
    }
    else
    {
        // Disable your integration with Play Games Services or show a login button
        // to ask users to sign-in. Clicking it should call
        // PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
    }
}

public void ShowLeaderboard()
{
    PlayGamesPlatform.Instance.ShowLeaderboardUI(leaderBoardId);
}

public void ShowAchievements()
{
    PlayGamesPlatform.Instance.ShowAchievementsUI();
}

public void UnlockAchievement(string achievementID)
{
    PlayGamesPlatform.Instance.ReportProgress(achievementID, 100.0f, (bool success) =>
    {
        if (success)
        {
            Debug.Log("Score reported successfully!");
        }
        else
        {
            Debug.LogError("Failed to report score.");
        }
    });
}

public void ReportScore(long score, string leaderboardID)
{
    PlayGamesPlatform.Instance.ReportScore(score, leaderboardID, (bool success) =>
    {
        if (success)
        {
            Debug.Log("Score reported successfully!");
        }
        else
        {
            Debug.LogError("Failed to report score.");
        }
    });
}

} `

I´ve tried everything I've seen about this error and similar ones. Custom Proguard file, fixing the file android dependencies, changing things inside the manifest, using resolve and force resolve, checking debug and release in minification... but none of those are working for me. Also changed the Sha1 from my play console inside developers hub. I'm still getting the error and I don't know what else do or try.

Please help.

Versions

Additional context It's a 2d game with 2d Core installed, Unity ads, another plugin for translations and nothing else. Shouldnt be a conflict with those.

EdgarGomez commented 11 months ago

This is still happening. Any ideas?

rami-al-rahim commented 9 months ago

Hi I tried to change this line of code in GooglePlayGamesPluginDependencies.xml form this <repository>Packages/com.google.play.games/Editor/m2repository</repository> to this <repository>Assets/GooglePlayGames/com.google.play.games/Editor/m2repository</repository> I hope this help you

theeugeneL commented 8 months ago

I'm using unity 2022.3.4f1 and GooglePlayGamesPlugin-0.11.01 Tried all of the above and nothing worked for me.

I fixed the issue by add this line of code in Plugins/Android/mainTemplate.gradle

dependencies {
    implementation "com.google.android.gms:play-services-games-v2:+"
  }
ZhangHuan0407 commented 7 months ago

unity 2021.3.33, plugin 0.11.01 This is still happening. Does anyone know what an Android project looks like when properly exported? image this file: Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/0.11.01/gpgs-plugin-support-0.11.01.srcaar if rename and unzip this file, open directory, rename and unzip classes.jar, you will find some class in folder classes - unzip\com\google\games\bridge I don't know what is .srcaar file. But my gut tells me that this file should be exported to an Android project, or unzipped to an Android project.

sameehj commented 7 months ago

I'm using unity 2022.3.4f1 and GooglePlayGamesPlugin-0.11.01 Tried all of the above and nothing worked for me.

I fixed the issue by add this line of code in Plugins/Android/mainTemplate.gradle

dependencies {
    implementation "com.google.android.gms:play-services-games-v2:+"
  }

This worked for me! Thank you SIR!

longshilin commented 6 months ago

Ref: https://github.com/googlesamples/unity-jar-resolver/issues/208

mattmisk commented 2 months ago

I'm using unity 2022.3.4f1 and GooglePlayGamesPlugin-0.11.01 Tried all of the above and nothing worked for me.

I fixed the issue by add this line of code in Plugins/Android/mainTemplate.gradle

dependencies {
    implementation "com.google.android.gms:play-services-games-v2:+"
  }

Thank you SO much!!!

pang0018 commented 1 week ago

You can also disable minify in the Player settings in Android (if you don't care about minifying the Android code)