# 谷歌登入 <!-- 頁首通用模組 --> {%hackmd xcsnQTMQQ0SZQ9QF7YUp_g %} --- ![](https://i.imgur.com/z4CASzm.png) [TOC] --- > ~~***I never try it.***~~ > ~~***I am trying it.***~~ > ~~***I do not want to try it again.***~~ > ~~***FUCK UNITY.***~~ > [name=Mibudin] --- ## Google Sign-In in Unity ### Preparation Note *(Imagined)* #### Unity Settings - ***Package Name*** - Following the **[Java Package Naming Specification](https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html)**. - *Setting Path*: `Edit > Project Settings > Palyer > <Platform> > Other Settings > Identification > Package Name` - ***Project Keystore*** - A **custom keystore** or a **debug keystore** *(in default)*. - *Setting Path*: `Edit > Project Settings > Palyer > <Platform> > Publishing Settings > Project Keystore` #### Google Cloud Platform Project - ***GCP Project*** > Following [this](https://developers.google.com/identity/sign-in/android/start) and [this](https://developers.google.com/identity/sign-in/ios/start). - ***Project Generation Guide*** - It MAY be easier and less difficulties to follow the tutorials of the official websites step-by-step. - For [**Android**](https://developers.google.com/identity/sign-in/android/start) / [**iOS**](https://developers.google.com/identity/sign-in/ios/start) - ***Platforms*** - For each platform *(**Android** / **iOS**)*, the client IDs corresponding to them should be generated respectively. - ***Package Name*** - The ***Package Name*** set in Unity. - ***SHA-1 Signing Certificate*** - Generate **SHA-1** of the ***Project Keystore***. **General Generation**: > Following [this](https://docs.oracle.com/javase/9/tools/keytool.htm), [this](https://developers.google.com/android/guides/client-auth), [this](https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/keytoolDocs/supportedkeystoretypes.html), and [this](https://stackoverflow.com/questions/8576732/there-is-no-debug-keystore-in-android-folder). - The **Keytool** to be used - `<JDK> > bin > keytool.exe` - Already in the environment paths generally. - The **Command** to be run ```shell keytool -list -v -alias <your-key-name> -keystore <path-to-production-keystore> ``` - The **Custom Keystore** - `-alias <?>`: The alias of the keystore. - `-keystore <?>`: The path of the keystore. - The **Debug Keystore** *(defaultly)* - `-alias <?>`: `androiddebugkey` - `-keystore <?>`: - *Mac/Linux*: `~/.android/debug.keystore` - *Windows*: `%USERPROFILE%\.android\debug.keystore` - Others - `-list`: List entries *(showing more informations)*. - `-v`: Target verbose output. - Exception - **[`Keystore file does not exist`](https://stackoverflow.com/questions/8576732/there-is-no-debug-keystore-in-android-folder)**: - This exception occurs if the default debug keystore does not exist there *(**never generated**)*. - You can run other associated program, software, or application to let them generate this file automatically. - Or **generate one manually**: ```shell keytool -genkey -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore -storepass android -keypass android -dname "C=US,O=Android,CN=Android Debug" -storetype PKCS12 -keyalg RSA -keysize 2048 -sigalg SHA1WithRSA -validity 10950 ``` - `-genkey`: Generate a key pair. - `-v`: Target verbose output. - `-alias <?>`: The alias of the keystore. *Default*: `androiddebugkey` - `-keystore <?>`: The path of the keystore. *Default*: - *Mac/Linux*: `~/.android/debug.keystore` - *Windows*: `%USERPROFILE%\.android\debug.keystore` - `-storepass <?>`: The store password of a keystore. *Default*: `android` - `-keypass <?>`: The key password of an entry. *Default*: `android` - `-dname <?>`: The distinguished name. *Default*: `"C=US,O=Android,CN=Android Debug"` - `-storetype <?>`: The keystore type. *Default*: `PKCS12` - `-keyalg <?>`: The key algorithm name. *Default*: `RSA` - `-keysize <?>`: The key bit size. *Default*: `2048` - `-sigalg <?>`: The signature algorithm name. *Default*: `SHA1WithRSA` - `-validity <?>`: The validity number of days. *Default*: `10950` (30 common years) - Or WHY NOT **create a custom keystore** in Unity. #### Google Sign-In Unity Plugin - ***Plugins*** > Following [this](https://medium.com/@capcomin/unity3d-google-signin-for-android-ios-games-fd59e4b6f027). - There are (maybe) two plugins to be needed - **Play Services Resolver for Unity** *(External Dependency Manager for Unity (EDM4U))* - Hereinafter called the **pre-plugin**. - *(MAYBE already in default Unity which installed all Android associated modules. Or...)* - **Google Sign-In Unity Plugin** - Hereinafter called the **plugin**. - The **pre-plugin** file from [here](https://github.com/googlesamples/unity-jar-resolver). - *(Download the Unity Package file in the root path of the source code.)* - The **plugin** and sample releases from [here](https://github.com/googlesamples/google-signin-unity). - *(Download the releases.)* - ***Import Process*** > Following [this](https://medium.com/@capcomin/unity3d-google-signin-for-android-ios-games-fd59e4b6f027). - *(If needed,)* Install the **Android Build Support**, **Android SDK & NDK Tools**, and **OpenJDK** modules of the Unity. - *(If needed,)* Remember to check whether **the paths to these modules or tools** pointed to the correct places where these internal or external things should be. - *Setting Path*: `Edit > Preferences > External Tools > Android > ...` - *(If needed(?),)* Switch the platform of Unity to **Android**. - *(If needed,)* Remove **TextMesh Pro**. - *(If needed to handle some weird exceptions; Or if this plugin is needed, it is a good attempt not to remove it.)* - *(If needed(?),)* Import the **pre-plugin**. - Import the **plugin** EXCEPT `./Parse/`. - *(If needed,)* Handle the exception of duplicated files **`Google.VersionHandler.dll`** - *(It MAY be better to delete the duplicated file in **plugin**)*. - Synchronize the **gradle files** in the project. - *Command Path*: `Assets > Play Services Resolver > Android Resolver > Resolve` and then `Assets > Play Services Resolver > Android Resolver > Force Resolve` - *Command Path*: *(alternative sometimes due to different versions maybe)* `Assets > External Dependency Manager > Android Resolver > Resolve` and then `Assets > External Dependency Manager > Android Resolver > Force Resolve` - *(If needed,)* Import the **sample scene**. - ***Web Client ID*** - The Web Client ID provided by ***GCP Project***. - This ID is needed to apply the main features of this **plugin**. - ***USE IT*** - Try to follow the provided **sample scene**. - It seems that there is no such an official document to this plugin. Maybe the **source codes** of the plugin and the **sample** help. - Or visit the official **[Google Sing-In](https://developers.google.com/identity/sign-in/web/sign-in)** website to understand the basic conceptions, maybe useful *(or not)*. ### Implement Note ***[秘](https://hackmd.io/8WnQ1K-FQYScCfvMtnFKOg)***