Hi everybody. After struggling for a few days with GoogleSignIn, I had decided to write this article.
Normally, the expectation from a SDK/Library is , they should be easy to implement and work like a charm.
Yes, the mobile world is rapidly changing and these new fancy dependency tools are being updated continuously. I know it’s not easy to handle but we are talking about Google and Unity3D. So thats why the expectations are high.
Personally I’m fan of simplification. As developers, if we are using any SDK, it should be piece of cake to reach out our expectations. For long years, I’d implemented maybe more than 50 different SDK but to be honest most of them were tricky and I’d spent too much effort to get to the point.
Ok, after a short introduction let the show begin.
I had prepared a simple checklist for Unity3D folks, but please after each step, make sure your code is building and running on a physical device successfully.
This demo game had been created from scratch and containing only GoogleSignIn Feature. For upcoming days, I’m planning to continue with 2nd article to integrate it to the Firebase Auth system.
You may think that some of these steps are so simple but all of us has not same experience:) Later better then never
1. For sure, create a new Unity3d project and switch your platform to the Android and update your package name( You will need the same package name in Firebase at next steps)
2. From Unity3D -> Window/PackageManager
Select TextMesh Pro and remove it :) Yes you don’t need to read again, please remove it. It’s weird but there are some errors occur, we can discuss later.
Removing TextMesh Pro
3. From here download “google-signin-plugin-1.0.3.unitypackage” file and then import package within Unity3D-> Assets/Import Package
When importing this package, there’s a small trick u need to know. You should exclude Parse folder. We will discuss these weird tricks later. Actually these are the key points where usually many developers like me lost hours/days. If you forget the exclude manually, don’t worry, you can delete that directory but keep in mind that it is safe to build&run the app on the real device.
4. Again from here (same page) download the “GoogleSignIn-sample.unitypackage”. I had used the 1.0.3. And then import the package within Unity3D-> Assets/Import Package
Keep in mind to build&run after each step. I had repeated these steps minimum 4 times to write this article,I have not faced any issue. But depends on your configurations, it’s always good to fasten your seat belt.
Now we are ready to setup our Firebase project. Before starting you need to know that you will need SHA1 which you can find at next steps.
5. From terminal go to the Keytool Directory which is there for usually MacOs: cd /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/bin
Then find your SHA1 value with:
keytool -list -v -keystore ~/.android/debug.keystore
Note: If you want to use your custom keystore , you can use with pointing it’s address
Note your SHA1, we will use it for firebase setup.
6. From firebase console, create new project and add your application with your package name and SHA1 value which you get from previous step.
7. Enable Google Sign In from console :
While enabling the Google , note down your WebClient ID, we will use it at Unity3D
8. Now , Unity3D need to sync your grade files, it’s easy to do it. From
Unity3D -> Assets -> Play Services Resolver -> Android Resolver ->
Resolve and then Force Resolve
This step will sync the required files.
9. Add the example GoogleSign scene from
Build&Run the application on Real Device
10. Select Canvas object from the scene, and from inspector put your WebClientId (step7) to the script component.
Boom, now you can get your google login token.
Please add your comments below. As you see I’m not adding any code to this demo. All I’m doing is listing down the required steps with helpful screenshots. After losing days, I believe this will help many people to implement Google Sign In.
You can also find the demo project at this Github link. (checkout development branch)
But you need to add your SHA1, WebClientId and set your Firebase project.
Previously published at https://medium.com/@capcomin/unity3d-google-signin-for-android-ios-games-fd59e4b6f027
Create your free account to unlock your custom reading experience.