playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.46k stars 965 forks source link

Possible Unintended Behaviour for Google Play Authentication Issues. #2531

Open Fall3nWarrior opened 5 years ago

Fall3nWarrior commented 5 years ago

Recently I started integrating the Play Games Plugin for Unity in my Game and ran across an issue where the game would fail to authenticate with Google Play Services. It failed 100% of the time.

After researching the issue further, checking my code implementation, Google Play Console settings and trying some of the steps that others did to remedy the situation, I discovered the problem. Unfortunately for me, none of the steps I found elsewhere solved the issue as my app signing keys matched up and all other settings were correct in the Google Play Console.

It was only after I compared the LollyGagger codelab here to the build settings of my game, that I found the problem. In Unity under File > Build Settings > Android Platform, if Development Build is checked then Google Play Services fails to authenticate 100% of the time in Development Builds. Therefore the solution is to uncheck the box.

Here is a screenshot of the setting in question. Build Settings

I am not sure if this is intended or a bug. I just wanted to share my solution so that I may help others who have been stuck and to report a possible unintended behaviour or bug.

legas1 commented 5 years ago

Looks like this is intented as Unity default template for Gradle lets Gradle sign the Development build with debug keystore, therefore if you uncheck it then it will use your release keystore. Workaround for this is letting Unity generate custom gradle template file and copypaste SIGNCONFIG from release section to debug one.

Teddymac22 commented 5 years ago

@Fall3nWarrior Thanks so much for verifying this. I seen where someone mentioned this in a post somewhere on the net, but I wasn't sure if this was the case. I have been struggling with this issue myself as shown in a recent post in this forum.

I am working on 2 projects that use the same game engine and one used Admob and the other did not. After updating GPS to 0.9.60 and Facebook SDK to 7.15.1 the one project without Admob worked correctly with Development Mode unchecked. This version has a Beta build out, but no Alpha or Production.

The project with Admob had all kinds of issues so I have finally just removed it and I am now attempting to get GPS working. Now, with this version, If I leave Development Mode unchecked Facebook nor GPS will even attempt to start. With GPS the callback is never used. With Development Mode checked, Facebook will work it seems and GPS shows it failed to authenticate. I have put this version into Alpha with the same results. This version has a Beta and a Production out that are both older than the Alpha.

So, I am wondering do you need to publish a version to Beta in order for the GPS to start authenticating? I will be testing this soon as it seems like in the past that this fixed issues I had before. It has been many months sense I posted an update so I can't remember what I did before.

Teddymac22 commented 5 years ago

Quick update. I just tested this with another project I have going that uses the same game engine. GPS and Facebook SDK both work for the app if Development Build is left unchecked. So the solution to uncheck the Development Build box does not apply to all situations. This app has a live Beta version but no Production version. So I wonder if the versions there are uploaded to the store factors into what GPS will allow?

legas1 commented 5 years ago

@Teddymac22 Does the solution I proposed above work for you?

Steps to make it happen are the following:

  1. Open Publishing Settings in Player Settings (Unity)
  2. Check Custom Gradle Template
  3. Let Unity generate mainTemplate.gradle file
  4. Open the generated file in some editor (ex Notepad++) and modify android -> buildTypes section as following:
    buildTypes {
        debug {
            minifyEnabled **MINIFY_DEBUG**
            useProguard **PROGUARD_DEBUG**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG** /* <- this is the key to sign dev build too */
            jniDebuggable true
        }
        release {
            minifyEnabled **MINIFY_RELEASE**
            useProguard **PROGUARD_RELEASE**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
        }
    }**PACKAGING_OPTIONS****SPLITS**
  5. Don't forget to remove Unity comment on first line!
Teddymac22 commented 5 years ago

@Noah1911 Oh my goodness, that worked! I am unfamiliar with Android Studio, Gradle, and the like, so I didn't understand what you originally suggested. This also allows for Facebook SDK to function and I bet Admob as well in one of my previous setups.

Ok, hear is a question... I have two projects using the same engine, with Project A if I uncheck Development Build, neither GPS or Facebook functions. But in Project B if I leave Development Build unchecked it works just fine. Project A has a live Production going, but Project B is in Open Beta.

GPS nor Facebook works on Project A when I download from the Play Store the internal or Alpha build. But it works now with a direct build to device and Development Build checked (thanks to Noah1911 solution).

I checked Project A's settings in the console and testing is turned on for Alpha and Internal. Perhaps it takes time for the GPS to kick in? Or do I need to publish it to Beta? The code obviously works as it works now in Development Mode so there has to be some other reason. I do not use the Google Signing feature on either project.

legas1 commented 5 years ago

@Teddymac22 Can you post adb's logcat log?

Teddymac22 commented 5 years ago

Here are a couple of logcats. One with GPS working in Development mode and and the one not working(logcatMissingGPS) was downloaded from the Google Play Store as a Alpha build. Noting works in the none working one, not even purchases and it has a line that says... E/Unity (29704): AndroidJavaException: java.lang.ClassNotFoundException: com.unity.purchasing.googleplay.GooglePlayPurchasing

E/Unity (29704): java.lang.ClassNotFoundException: com.unity.purchasing.googleplay.GooglePlayPurchasing

So, why are the needed classes not being used?

BTW, the android device used is an old samsung phone with no cell data that's just being used for testing. The other project I have works fine on it, GPSs and all.

And everything worked just fine until updated Unity to 2018.3.8 and went to a Gradle build and then updaed Facebook SDK and GPS sdk.

logcatWihtGPS.txt logcatMissingGPS.txt

Fall3nWarrior commented 5 years ago

@Noah1911 Thank you for your explanation and the step by step tutorial. It worked perfectly for me and cleared up any confusion!

Fall3nWarrior commented 5 years ago

@Teddymac22 Your welcome for verifying this for you. Unfortunately, I don't think I can help you with your issue as I am new to all of this myself. But I'm sure that @Noah1911 or someone else can help. Good luck!