playgameservices / cpp-android-basic-samples

Sample games using the Google Play Games C++ SDK
302 stars 133 forks source link

[BUG] Initialization of GPGS 21 fails with Can't register class com/google/android/gms/games/multiplayer/*: an exception occurred. #67

Open solodon4 opened 3 years ago

solodon4 commented 3 years ago

When I am using the latest implementation com.google.android.gms:play-services-games:21.0.0 I get the following errors when trying to create gpg::GameServices object:

E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/Invitation: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/InvitationBuffer: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/Invitations: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/Invitations$LoadInvitationsResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/Multiplayer: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/Participant: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/ParticipantResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/LoadMatchesResponse: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMatch: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMatchBuffer: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMatchConfig: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMatchConfig$Builder: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMultiplayer: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMultiplayer$CancelMatchResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMultiplayer$InitiateMatchResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMultiplayer$LeaveMatchResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMultiplayer$LoadMatchesResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMultiplayer$LoadMatchResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/turnbased/TurnBasedMultiplayer$UpdateMatchResult: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/realtime/RealTimeMessageReceivedListener: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/realtime/RealTimeMultiplayer: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/realtime/RealTimeMessage: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/realtime/Room: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/realtime/RoomConfig: an exception occurred.
E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/realtime/RoomConfig$Builder: an exception occurred.
E/GamesNativeSDK: Could not register one or more required Java classes.

I am fully aware that Google has ended support for multiplayer APIs on March 31, 2020 and it seems that version 21 of play games services is the first version in which that functionality has actually been removed, which would explain why initialization fails. However, my app does not use any multiplayer APIs, so the problem is entirely on Google's side, possibly in one of the dependencies trying to access those APIs.

Here is a full list of my dependencies for reference:

    // Google Play Services
    implementation 'com.google.android.gms:play-services-auth:19.2.0'
    implementation 'com.google.android.gms:play-services-base:17.6.0'
    implementation 'com.google.android.gms:play-services-games:20.0.0'
    implementation 'com.google.android.gms:play-services-nearby:18.0.0'

    // From: https://firebase.google.com/docs/auth/cpp/play-games#ndk-build
    implementation(name:'google-signin-cpp-release', ext:'aar')

    // Chartboost: https://answers.chartboost.com/en-us/child_article/android-integration
    implementation 'com.chartboost:chartboost-sdk:8.2.0'

    // AdMob Mediation
    // See: https://github.com/firebase/firebase-cpp-sdk/issues/621
    implementation 'com.google.ads.mediation:adcolony:4.4.1.0'
    implementation 'com.google.ads.mediation:chartboost:8.2.0.0'

    // Mediation Test Suite
    // See: https://github.com/firebase/firebase-cpp-sdk/issues/621
    implementation 'com.google.android.ads:mediation-test-suite:1.5.0'

    // Firebase
    implementation 'com.google.firebase:firebase-analytics:19.0.0'
    implementation 'com.google.firebase:firebase-ads:19.8.0'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-dynamic-links:20.1.1'
    implementation 'com.google.firebase:firebase-config:21.0.0'
    implementation 'com.google.firebase:firebase-crashlytics-ndk:18.2.0'
    implementation 'com.google.firebase:firebase-perf:20.0.2'
    implementation 'com.google.firebase:firebase-storage:20.0.0'

After weeks of trying various combinations fo versions I came up with the following workaround: if I downgrade version to com.google.android.gms:play-services-games:20.0.0, which is the latest version where those classes were still present, as well as include an additional package not mentioned in the documentation as relevant to anything I do: com.google.android.gms:play-services-nearby:18.0.0 I end up not getting any E/GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/xxxxxx: an exception occurred. errors and am able to successfully create gpg::GameServices object.

Again, I don’t use any of the multiplayer functionality or nearby discovery so I guess one of your dependencies either in GPGS or in Firebase must be causing the problem.

P.S. Versions not mentioned above: