play-games-plugin-for-unity icon indicating copy to clipboard operation
play-games-plugin-for-unity copied to clipboard

Error In LogCat - com.google.games.bridge.HelperFragment

Open AndrewCooper69 opened this issue 2 years ago • 15 comments

I am using CloudOnce v2.7.1. When I run my project on an Android device, I get the following error in logcat:

"*** [Play Games Plugin 0.10.10] 11-24-21 15:40:41 -05:00 ERROR: Exception launching token request: java.lang.ClassNotFoundException: com.google.games.bridge.HelperFragment"

The plugin doesn't log in to cloud services because of this error. I have 3 questions:

  1. Are you familiar with this error, and know any fixes?
  2. Would updating my CloudOnce to V2.7.4 fix this, or updating my GPGS?
  3. If yes, how would one install an updated package? Do you just go to Import Package > Custom Package > CloudOnce V2.7.4.unitypackage > Add all files it suggests? Do you have to remove the older 2.7.1 version somehow?

Thank you!

AndrewCooper69 avatar Nov 29 '21 19:11 AndrewCooper69

HelperFragment is a java class, which is a part of this plugin that talks with the Java SDK. As it is a part of this plugin, just importing this plugin into your project must be sufficient to have that class. The exception is ClassNotFoundException, so when building your project, it somehow gets stripped out of your build.

The likely scenario is that minify is enabled in the project settings and you do not have custom proguard rules or are missing some important ones. Please take a look at here.

ozdemir08 avatar Nov 30 '21 05:11 ozdemir08

That is incredibly helpful, thank you very much! However, I did not have Minify active. I activated it, and tried to add a custom proguard file with the contents listed here, but unfortunately the issue still persists. Here is the error, and one more I forgot to mention in my last message:

*** [Play Games Plugin 0.10.10] 11-30-21 15:13:53 -05:00 ERROR: Exception launching token request: java.lang.ClassNotFoundException: com.google.games.bridge.HelperFragment *** [Play Games Plugin 0.10.10] 11-30-21 15:23:29 -05:00 ERROR: UnityEngine.AndroidJavaException: java.lang.ClassNotFoundException: com.google.games.bridge.HelperFragment

Do I need to add another element to the proguard file which is not listed in the link above? Perhaps I need to add:

  • keep class com.google.games.bridge.** { *; }

Thank you!

AndrewCooper69 avatar Nov 30 '21 20:11 AndrewCooper69

One more thing to note - when I try to build the Google Play Bundle version of the app (not .apk, but .aab) with Minify active, the build fails and says the following:

java.io.IOException: java.lang.IllegalArgumentException: Can't find common super class of (com/google/android/gms/common/a) (with 4 known super classes) and (com/google/android/gms/common/e) (with 1 known super classes) See console for details.

It does not happen when I deselect Minify.

Perhaps the issue is that my version of Play Games Services does not match the proguard information listed in that link above?

Thank you for the help!

AndrewCooper69 avatar Nov 30 '21 21:11 AndrewCooper69

keep class com.google.games.bridge.** { *; } See line 16

I would first go with trying out building the plugin as .apk and check if it works. Then if it works I would continue with whether you can build it as .aab .

You should not need adding extra proguard rules actually. However, if your project also includes other android libraries, then the rules in that list would not be enough. The way proguard works is starting from the classes that match with the keep rules, it keeps all used classes and strips out the rest. So, if you need other libraries and are getting ClassNotFound or similar errors, then you can go ahead with adding a new rule for each missing class.

ozdemir08 avatar Dec 01 '21 14:12 ozdemir08

Thank you for all your help. When I build the .apk it does build but still get the same error in logcat, and it does not build the .aab if Minify is enabled.

I am starting to think there will be no solution here, as I have added the proguard file with those lines, but still am getting the same error. Perhaps it is a weird combination of the CloudOnce plugin and my version of Unity, or something like that.

If anyone is able to help me via Discord, or if it would help to post a video, let me know! Thank you!

AndrewCooper69 avatar Dec 01 '21 20:12 AndrewCooper69

Hi @AndrewCooper69 did you find a solution to your issue?

haritonstefan avatar Dec 28 '21 14:12 haritonstefan

Hi @AndrewCooper69 did you find a solution to your issue?

I have not found a solution no. If you have any ideas on how to help, I would appreciate it!

The game is currently released on the Google Play Store under the name Rhythm Royale. If you would like to check it out, you may be able to see the logcat output from the game itself if you have developer mode enabled. We decided to switch the leaderboards to a scoreboard saved internally on a phone, but obviously a shared leaderboard would be preferable.

Andrew Cooper

AndrewCooper69 avatar Jan 04 '22 19:01 AndrewCooper69

Yep, that is exactly my problem and still searching for a solution.

aeaktepe avatar Mar 28 '22 15:03 aeaktepe

Yep, that is exactly my problem and still searching for a solution.

Unfortunately I was never able to find a solution. We ended up releasing the game and closing out development without Leaderboards. It sucks, because we really wanted them in there, but no solution was found!

AndrewCooper69 avatar Mar 28 '22 15:03 AndrewCooper69

I want to make an edit on my post. In between the builds (on my previous post) I was trying many things try to fix the issue, I though the below was the solution that worked but apparently it did not. Yesterday, I removed Google Ads plugin (will work with unity ads), and re-installed playgameservices plugin just to make sure. The problem came back and below solution was not working anymore...

Again after many trials, I made it work. I'm still not sure which one but it has to be one of the below (maybe both). Second one sounds silly yet it's the same step I did also in the previous fix.

1- Unchecked Minify on Release from build. ShowLeaderBoardUI started working on this build. (most certain way for me but not ideal) 2- While building the previous step, I was checking AndroidHelperFragment.cs and just because of boredom, I refactored using statements in this class to the short one. Then I checked Minify on Release and Use R8 (this was normally disabled) and again it worked.... Maybe it's due to incremental building but still it's working in this state.

--- IGNORE THIS OLD SOLUTION--- Thank you Andrew, fortunately for me I just find a solution?

In my proguard file, below line was already there. -keep class com.google.games.bridge.** { *; }

But apparently that was not enough, so in one of my tries I saw a post about adding below lines and it did work for me. So in case anyone sees this, they may try this solution.

-keep class com.google.games.** { *; }
-keep interface com.google.games.** { *; }

aeaktepe avatar Mar 28 '22 18:03 aeaktepe

I don't have proguard but unchecking minify worked for me. Which is a shame I want it to work with minify 😩

RomainBitard avatar Apr 18 '23 15:04 RomainBitard

Having the same issue, adding -keep class com.google.games.** { ; } -keep interface com.google.games.* { *; } has not worked for me, neither has removing minify options. Not sure what to do.

danniboy1234 avatar May 14 '23 22:05 danniboy1234

raziel619's solution was not suitable for me since it leads to other build errors related to many other 3rd party SDK. I'll copy it over here anyway for preservation purpose.

Solution

To solve this, we need to tell the android build system to keep all of the classes needed by both GPG and GMA. This can be done by providing a custom proguard-user.txt file. First, the proguard-user.txt file in the Assets/Plugins/Android. Copy and paste the content below into this new file.

-dontwarn com.google.vr.ndk.base.DaydreamApi
-keep class com.facebook.** {
   *;
}
-keep class com.google.unity.** {
   *;
}
-keep public class com.google.android.gms.ads.**{
   public *;
}
-keep class com.google.android.gms.games.leaderboard.** { *; }
-keep class com.google.android.gms.games.snapshot.** { *; }
-keep class com.google.android.gms.games.achievement.** { *; }
-keep class com.google.android.gms.games.event.** { *; }
-keep class com.google.android.gms.games.stats.** { *; }
-keep class com.google.android.gms.games.video.** { *; }
-keep class com.google.android.gms.games.* { *; }
-keep class com.google.android.gms.common.api.ResultCallback { *; }
-keep class com.google.android.gms.signin.** { *; }
-keep class com.google.android.gms.dynamic.** { *; }
-keep class com.google.android.gms.dynamite.** { *; }
-keep class com.google.android.gms.tasks.** { *; }
-keep class com.google.android.gms.security.** { *; }
-keep class com.google.android.gms.base.** { *; }
-keep class com.google.android.gms.actions.** { *; }
-keep class com.google.games.bridge.** { *; }
-keep class com.google.android.gms.common.ConnectionResult { *; }
-keep class com.google.android.gms.common.GooglePlayServicesUtil { *; }
-keep class com.google.android.gms.common.api.** { *; }
-keep class com.google.android.gms.common.data.DataBufferUtils { *; }
-keep class com.google.android.gms.games.quest.** { *; }
-keep class com.google.android.gms.nearby.** { *; }
-keep public class com.google.ads.**{
   public *;
}
-keepattributes *Annotation*
-dontobfuscate

Next, enable Custom Gradle Properties Template and Custom Proguard File in Unity’s Player Settings as shown in the image below.

Ensure that unity is pointing to your newly created proguard text file. (Note the Custom Gradle Properties Template option may be unnecessary).

cdr9042 avatar Feb 28 '24 03:02 cdr9042

I got it working. The Select save UI displayed successfully. I didn't have to touch minify or proguard.

Edit this file: Assets/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPluginDependencies.xml Change the line <repository>Packages/com.google.play.games/Editor/m2repository</repository> to: <repository>Assets/GooglePlayGames/com.google.play.games/Editor/m2repository</repository>

Make EDM4U Resolve or Force resolve.

If the resolver worked correctly, there should be plugin files in Assets/GeneratedLocalRepo/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/0.11.01/gpgs-plugin-support-0.11.01.aar and gpgs-plugin-support-0.11.01.pom

If resolver didn't work, try manually copying files from Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/0.11.01 and rename .srcaar to .aar

The mainTemplate.gradle should have this line:

maven {
            url (unityProjectPath + "/Assets/GeneratedLocalRepo/GooglePlayGames/com.google.play.games/Editor/m2repository") // Assets/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPluginDependencies.xml:11
        }

The file ProjectSettings\AndroidResolverDependencies.xml should have these lines:

<file>Assets/GeneratedLocalRepo/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/0.11.01/gpgs-plugin-support-0.11.01.aar</file
<file>Assets/GeneratedLocalRepo/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/0.11.01/gpgs-plugin-support-0.11.01.pom</file>

cdr9042 avatar Feb 29 '24 04:02 cdr9042