Teach you how to quickly run Unity Huawei games (GameService)

Background introduction

Huawei Game Service SDK provides multiple capabilities such as game application self-upgrade detection, player information acquisition, game buoys, anti-addiction, achievements, leaderboards, etc. Unity provides HMS to facilitate global developers to quickly integrate these capabilities and release Huawei channels. Core App Services SDK and demo.

This post will test the water first and try the capabilities of this SDK.

Goal: Run the game demo provided by Unity, and be able to debug through basic functional interfaces, such as init and login with HUAWEI ID. If you have not installed Unity yet or have questions about Unity packaging, please refer to Unity Editor Installation and Apk Packaging: https://developer.huawei.com/consumer/cn/forum/topic/0204405811539110247?fid=18

Document link

https://docs.unity.cn/cn/Packages-cn/[email protected]/manual/appgalleryChinese.html

Demo download path

https://github.com/Unity-Technologies/HMSSDKSample

The demo we need to run is this:

Insert picture description here

Preparation before operation

Step 1: Register as a Huawei developer and create an application.
This step will not be repeated, please refer to Huawei official documents:https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/appgallerykit-preparation-game

Insert picture description here

I created it as follows:

Insert picture description here

Step 2: Download the agconnect-services.json file from Huawei background

  1. After creating the application, switch the project associated with the application, the interface will have the following prompt, here I chose "Manually enter the package name"

Insert picture description here

Insert picture description here

  1. Download the agconnect-services.json file

Insert picture description here

Step 3: Replace the json file in the demo provided by Unity.
Replace the json file downloaded in step 2 with the following file.

Insert picture description here

Step 4: Configure the following files in Assets/Plugins/Android.
Here, we refer to the following chapters of the documents provided by the unity official website to complete the relevant configuration, and will not repeat them.

https://docs.unity.cn/cn/Packages-cn/[email protected]/manual/appgalleryChinese.html#1-%E4%BB%8Eunity-asset-store%E5%AF%BC%E5%85%A5%E6%AD%A4%E5%8D%8E%E4%B8%BAhms-core-app-services-sdk

Insert picture description here

Use Unity Editor to open the demo

By default, you have installed the Unity Editor normally. If you have not installed it, please install it yourself. I am here to refer to the Unity Hub and the 2020.1.2f1c1 version of Unity Editor installed by referring to the following post.

https://developer.huawei.com/consumer/cn/forum/topic/0204405811539110247?fid=18

Step 1: Open Unity Hub and add the project provided by Unity

Insert picture description here

The results are as follows:

Insert picture description here

Note: When opening, pay attention to selecting the correct Unity version.
Step 2: Double-click the above item to enter the Unity Editor interface.

Insert picture description here

No need to pay attention to this prompt, because the version number of the Editor that I installed locally is different from the version of the editor used by Unity for this demo, select "Continue".

Insert picture description here

Select "Continue" and wait for the project to be imported.

Finally, successfully enter the Editor, the interface is as follows:

Insert picture description here

Complete the Android Build Settings settings.

Step 1: Select "File> Build Settings"

Insert picture description here

Step 2: Select the following, click "Player Settings" to enter the project settings page.
Note: Users who have not installed the Android module need to install the Android module in the editor according to the instructions. After installing the Android module, you need to restart the editor to take effect.

Insert picture description here

Step 3: Replace your own application information according to the application information you created on the Huawei AGC platform, including package name, version number, etc.

Insert picture description here

Insert picture description here

Step 4: Refer to the following steps to generate your own application signature file.

Insert picture description here

Note: If the JDK path does not exist or is empty, please go to Preference->External Tools to modify the default JDK path. The system will automatically detect, if not detected, please install it yourself and restart the editor to try again. Refer to the video JDK not found Unity | java development kit is not set or invalid unity.

Insert picture description here

I have placed the generated signature file here, and it has been successfully generated here.

Insert picture description here

Generate and configure signing certificate fingerprint

Use the above signature file, refer to Huawei's document to generate the fingerprint of the signature certificate and configure the fingerprint in the Huawei AGC system.

https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/appgallerykit-preparation#h2-1604041794639

Insert picture description here

Package Run Program

Step 1: Select "Switch Platform" to switch platform to Android phone.

Insert picture description here

Step 2: Select "Build And Run" and select the signature file just now.

Insert picture description here

The interface will prompt as follows:

Insert picture description here

Seeing this prompt means that the launcherTemplate.gradle file under my project Assets\Plugins\Android uses a deprecated method. To solve this problem, I can manually delete the "useProguard" in this file. Here I chose to delete manually, and delete the two lines marked in red below.

Insert picture description here

Repackage and run, the demo has been normally installed on the phone.

Step 3: Check whether the packaged demo is normal.
After packaging, the demo runs as follows.

Insert picture description here

Click the log information on the init interface to indicate success.

Insert picture description here

Click the Login>login button to open the HUAWEI ID login interface normally.

Insert picture description here

So far, it shows that the demo has been successfully run. We can check Unity's interface call method on the demo in the following file, and continue to debug and run the relevant Huawei interfaces.

Note: If you click the Login>login button to log in and fail and error 6003 is reported, please refer to Error 6003 when calling the HMS SDK interface . The most likely reason is that the signature fingerprint has changed after the signature file build is selected.

Insert picture description here

For more details, please see:

Unity Editor installation and Apk packaging:https://developer.huawei.com/consumer/cn/forum/topic/0204405811539110247?fid=18


Original link:https://developer.huawei.com/consumer/cn/forum/topic/0201418722921820534?fid=18

Author: Mayism

Guess you like

Origin blog.51cto.com/14772288/2601997