Build Runtime Quick Game using Cocos Creator - Part 3 - Huawei Developers

Introduction
Are you new to Quick game?
If yes, follow my previous articles understand basics about Quick Game.
Beginner: Find the Explanation of Quick Game Part 1
Beginner: Tic Tac Toe Game using HTML5 Quick Game - Part 2
In this article, we will learn how to build the Runtime Quick using Cocos Creator.
What is runtime quick game?
After runtime quick games based on RPKs developed by different development tools (Like Cocos Creator, LayaAir, Egret) are released on AppGallery, they can be loaded and run on Quick App Center.
Creating Quick Game
Step 1: Register as a Huawei developer and pass identity verification on HUAWEI Developers.
Step 2: Set up the development environment, including installing development tools on the PC and Quick App Loader (for mobile phones and tablets) on the test device.
Step 3: Sign in to AppGallery Connect and click My apps.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Step 4: Click New App.
Step 5: Add all required information, then click OK.
Parameters information.
Step 6: Navigate to Project settings > General information add package details.
Step 7: Add Default data processing location.
Generating and configuring a certificate fingerprint.
Create certificate
Step 1: Open Quick App IDE and open an existing project or create new project.
Step 2: Choose Tools > Certificate
Step 3: If signature is not yet created, select Create else if already exist select Import.
Step 4: Add necessary information and click Create.
Step 5: Copy SHA-256 certificate fingerprint from output.
Configure the Certificate fingerprint in AppGallery
Step 1: Sign in to AppGallery and click My project.
Step 2: Select the project which you want to configure the certificate fingerprint.
Step 3: Navigate to Project Settings > General information in the App information and enter the copied SHA-256 certificate.
Enable Game service.
Step 1: Sign in to AppGallery and click My project.
Step 2: Select the project which you want to enable Game service and Account kit.
Step 3: Navigate to Project settings > Manage APIs and enable Account Kit and Game Service.
Install Runtime Quick Game development tool
Cocos Creator
To use Cocos Creator to develop a quick game, visit the Cocos official website to obtain Cocos Creator 2.0.7 or later and install it.
LayaAir IDE
To use LayaAir IDE to develop a quick game, visit the Laya official website, obtain the installation package of the required version, and install it.
Egret Engine
To use Egret Engine to develop a quick game, visit the Egret official website, obtain the EgretLauncher and Egret Wing installation packages of the required versions, and install them.
Building Application in Cocos Creator.
Step 1: Open Cocos Dashboard. Choose Project and click New.
Step 2: You can select type of project and Click on Create and open.
Empty(2D)
Empty(3D)
Hello world
Example Taxi Game
In this article, I will choose Example Taxi Game
Step 3: Navigate to Project > Build.
Step 4: Set the parameters by referring to the following figure. The values of the parameters must be the same as those in the manifest.json file.
Step 5: Select Huawei Quick Game for Platform. After configuring all relevant items, click Build. The RPK is generated in the build/huawei/dist directory of the project.
Enter the required details. Select Build and make.
Step 5: Connect your phone to a computer using a USB cable and enable the developer mode.
For details, please refer to Enabling the Developer Options on a Huawei Phone.
Step 6: Click Play on the Build page.
On the displayed QuickGame DevTools page, click the run icon to run the game on the mobile phone.
Step 7: If you do not have devices, you can also run on the browser.
Result
Tips and Tricks
Understand About Quick Game.
Explore some Quick Game from phone.
Install all the required tools.
Make sure you have configured the adb in the desktop or laptop.
Command to install Quick App loader APK is adb install quickapploader.apk
Enable Game Service and Account Kit.
Conclusion
In this article, we have learnt about creating Quick Game using Cocos Creator, generating and configuring the SHA-256 fingerprint certificate, Enabling game service and account kit and building Runtime Quick Game application.
Reference
Quick Game official document
Download tools from here
Beginner: Find the Explanation of Quick Game Part 1
Beginner: Tic Tac Toe Game using HTML5 Quick Game - Part 2

Thanks for sharing!!!

Related

Cocos Creator Integrates with AppGallery Connect APM – Releasing a Cocos-based App

According to the introduction of Cocos Creator from its official website, Cocos Creator 2.4.1 and later versions support HUAWEI AppGallery Connect and have been providing multiple AppGallery Connect services. The following figure shows all supported AppGallery Connect services.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
To test how well Cocos supports AppGallery Connect services, this article uses the App Performance Management (APM) service as an example to monitor the performance data of a Cocos-developed app. First, let's see what APM is.
AppGallery Connect APM
APM of AppGallery Connect provides minute-level app performance monitoring capabilities. You can view and analyze app performance data collected by APM in AppGallery Connect to comprehensively understand the performance features of developed apps, helping you quickly and accurately rectify possible performance problems and continuously improve user experience.
That is, APM can help you monitor your app performance data in a variety of scenarios, including app launch, page loading, and network request. We can assume that APM can quickly locate performance-related problems for games, which attach great importance to performance as it greatly affects user experience.
Before You Start
Downloading and Installing the Cocos Dashboard
1. The Cocos Dashboard is the GUI-based development tool provided by Cocos. You can download it from https://www.cocos.com/creator/ (latest version: 2.4.2).
2. You need to install the Visual Studio as well to obtain the Cocos dependency package. The following figure shows the installation procedure.
3. After the installation is complete, click Run
Downloading and Installing Cocos Creator
1. Open the Cocos Dashboard and click Signin in the upper right corner. You can sign up first if you do not have an account.
2. After sign-in, click Editor on the left, and then click Download in the lower right corner.
3. On the Editor page, select the latest version of Cocos Creator, click the download button on the right, and agree with the terms.
4. Once the download is complete, you can create a Cocos project on the Project page. Take a HelloWorld project as an example.
5. When you open the project for the first time, the system prompts you to select a language. Just select English. Select the corresponding running environment and click Run.
Configuring the Visual Studio Code Compilation Environment
The built-in code editor of Cocos is too simple and is only suitable for code viewing and a small amount of editing. Therefore, we need a more mature and powerful compilation environment. This is where Visual Studio Code comes in.
1. Download and install Visual Studio Code of the required version based on your computer environment.
2. Open your project in Cocos Creator and choose Developer > VS Code Workflow > Install VS Code Extension from the main menu to add an adaptation plug-in to Cocos Creator.
3. If the information shown in the following figure is displayed, the installation is successful.
4. If you want the system to autocomplete the Cocos Creator engine API during coding, you need to generate the API autocompletion data and put the data in the project path through the menu. Choose Developer > VS Code Workflow > Update VS Code API Source.
5. Double-click the HelloWorld.js script in the project directory. In the dialog box that is displayed, click Yes and select Visual Studio Code as the default editor.
6. Double-click the HelloWorld.js script again to develop your app.
Packaging and Releasing a Cocos-based App in AppGallery Connect
Cocos Creator 2.4.1 and later versions allow you to package and release your app to HUAWEI AppGallery through AppGallery Connect. In addition, Cocos Creator suports various AppGallery Connect services, such as APM, which can be quickly integrated and used. The detailed procedure is as follows:
1. Sign in to AppGallery Connect and create an app.
2. Sign in to Cocos Creator, choose Project > Build…, and select HUAWEI AppGallery Connect as the release platform.
3. Click Build. If Built huawei-agc successfully is displayed, the build is successful.
Note: When you build a project for the first time, you need to choose File > Settings… and configure the Android SDK path and NDK path on the native development environment page.
4. Click Compile and wait until the compilation is successful.
5. A jsb-default or jsb-link directory (depending on the template selected on the Build… panel) is generated in the build directory of the default release path. AppGallery Connect services are automatically integrated in the directory. Open the publish directory in the jsb-link directory to view the generated APK file.
6. Upload the packaged APK file locally or using AppGallery Connect.
l Uploading the file on the Upload... panel.
a) Login Type: OAuth
Click Confirm, sign in to your HUAWEI ID (with sufficient permissions), and select the check box of the corresponding permissions. The APK file will be uploaded automatically.
b) Login Type: API Client
Sign in to AppGallery Connect to obtain related configuration. Go to Users and permissions > Connect API > Create, create an API client, select a role as required, and click OK.
Enter your client ID and key of the API client in the text boxes on the Upload... panel in Cocos Creator. Click Confirm.
After the APK file is uploaded successfully, you can view it in AppGallery Connect.
Uploading the file in AppGallery Connect
Click Upload and select the APK generated by Cocos Creator.
For more details, please refer to:
Cocos official documents
AppGallery Connect APM development guide
AppGallery Connect console
GitHub to download demos and sample codes
Stack Overflow to solve any integration problems​

Cocos Creator Integrates with AppGallery Connect APM - Releasing a Cocos-based App

According to the introduction of Cocos Creator from its official website, Cocos Creator 2.4.1 and later versions support HUAWEI AppGallery Connect and have been providing multiple AppGallery Connect services. The following figure shows all supported AppGallery Connect services.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
To test how well Cocos supports AppGallery Connect services, this article uses the App Performance Management (APM) service as an example to monitor the performance data of a Cocos-developed app. First, let's see what APM is.
AppGallery Connect APM
APM of AppGallery Connect provides minute-level app performance monitoring capabilities. You can view and analyze app performance data collected by APM in AppGallery Connect to comprehensively understand the performance features of developed apps, helping you quickly and accurately rectify possible performance problems and continuously improve user experience.
That is, APM can help you monitor your app performance data in a variety of scenarios, including app launch, page loading, and network request. We can assume that APM can quickly locate performance-related problems for games, which attach great importance to performance as it greatly affects user experience.
Before You Start
Downloading and Installing the Cocos Dashboard
The Cocos Dashboard is the GUI-based development tool provided by Cocos. You can download it from (latest version: 2.4.2).
2. You need to install the Visual Studio as well to obtain the Cocos dependency package. The following figure shows the installation procedure.
3. After the installation is complete, click Run
Downloading and Installing Cocos Creator
1. Open the Cocos Dashboard and click Signin in the upper right corner. You can sign up first if you do not have an account.
2. After sign-in, click Editor on the left, and then click Download in the lower right corner.
3. On the Editor page, select the latest version of Cocos Creator, click the download button on the right, and agree with the terms.
4. Once the download is complete, you can create a Cocos project on the Project page. Take a HelloWorld project as an example.
5. When you open the project for the first time, the system prompts you to select a language. Just select English. Select the corresponding running environment and click Run.
Configuring the Visual Studio Code Compilation Environment
The built-in code editor of Cocos is too simple and is only suitable for code viewing and a small amount of editing. Therefore, we need a more mature and powerful compilation environment. This is where Visual Studio Code comes in.
1. Download and install Visual Studio Code of the required version based on your computer environment.
2. Open your project in Cocos Creator and choose Developer > VS Code Workflow > Install VS Code Extension from the main menu to add an adaptation plug-in to Cocos Creator.
3. If the information shown in the following figure is displayed, the installation is successful.
4. If you want the system to autocomplete the Cocos Creator engine API during coding, you need to generate the API autocompletion data and put the data in the project path through the menu. Choose Developer >
VS Code Workflow > Update VS Code API Source.
5. Double-click the HelloWorld.js script in the project directory. In the dialog box that is displayed, click Yes and select Visual Studio Code as the default editor.
6. Double-click the HelloWorld.js script again to develop your app.
Packaging and Releasing a Cocos-based App in AppGallery Connect
Cocos Creator 2.4.1 and later versions allow you to package and release your app to HUAWEI AppGallery through AppGallery Connect. In addition, Cocos Creator suports various AppGallery Connect services, such as APM, which can be quickly integrated and used. The detailed procedure is as follows:
1. Sign in to AppGallery Connect and create an app.
2. Sign in to Cocos Creator, choose Project > Build…, and select HUAWEI AppGallery Connect as the release platform.
3. Click Build. If Built huawei-agc successfully is displayed, the build is successful.
Note: When you build a project for the first time, you need to choose File > Settings… and configure the Android SDK path and NDK path on the native development environment page.
4. Click Compile and wait until the compilation is successful.
5. A jsb-default or jsb-link directory (depending on the template selected on the Build… panel) is generated in the build directory of the default release path. AppGallery Connect services are automatically integrated in the directory. Open the publish directory in the jsb-link directory to view the generated APK file.
6. Upload the packaged APK file locally or using AppGallery Connect.
Uploading the file on the Upload… panel.
a) Login Type: OAuth
Click Confirm, sign in to your HUAWEI ID (with sufficient permissions), and select the check box of the corresponding permissions. The APK file will be uploaded automatically.
b) Login Type: API Client
Sign in to AppGallery Connect to obtain related configuration. Go to Users and permissions > Connect API > Create, create an API client, select a role as required, and click OK.
Enter your client ID and key of the API client in the text boxes on the Upload… panel in Cocos Creator. Click Confirm.
After the APK file is uploaded successfully, you can view it in AppGallery Connect.
Uploading the file in AppGallery Connect
Click Upload and select the APK generated by Cocos Creator.
great
It's very useful. Recently, our Cocos project is focusing on Huawei AppGallery.

Coding-free Integration of AppGallery Connect Crash into a Cocos-based App

The Crash service of AppGallery Connect provides a simple, coding-free solution for app crashes. It is found that Cocos Creator also supports the Crash service provided by AppGallery Connect. Let’s see how it works.If you want to quickly experience this service, see the demo on GitHub.
1. Creating an App and Enabling the Crash Service
1.1 Setting a Cocos App ID
Cocos app ID is the unique identifier of a game app. Before using services, you need to set a Cocos app ID for your game project.
If you do not have a Cocos-based game, click Dashboard to create one in the Cocos Account Center, as shown in the following figure.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
In the Cocos Account Center, click Create a game, complete your game information, and obtain the generated app ID.
Return to Cocos Creator, click Set Cocos AppID, and choose the game to associate it.
1.2 Enabling HUAWEI Analytics and Crash in Cocos Creator
In the Service panel, enable HUAWEI Analytics and Crash.
You can also view the enabled services (highlighted) in the Cocos Account Center, as shown in the following figure.
1.3 Enabling HUAWEI Analytics and Crash in AppGallery Connect
You also need to enable the services in AppGallery Connect. The steps are as follows:
a) Sign in to AppGallery Connect, create a project, and add an app to it. For details about how to create an app in AppGallery Connect, check the official documentation.
b) In AppGallery Connect, click My projects, select a project, go to Quality > Crash, and click Enable now to enable both HUAWEI Analytics and Crash.
c) Go to Project settings and download the latest agconnect-services.json file.
d) Save the downloaded agconnect-services.json file to the settings directory in your Cocos project.
The file is also displayed in Cocos Creator, as shown in the following figure.
2. Building and Installing an App
2.1 Releasing your app in AppGallery Connect
a) In Cocos Creator, go to Project > Build…, choose HUAWEI AppGallery Connect, and set a package name. The package name must be the same as that configured in AppGallery Connect. Otherwise, a compilation error will be reported.
b) Click Build, and then Compile. You can find the corresponding APK file in the \build\jsb-link\publish\android directory of the project. You can run the adb command after a USB cable has been connected to install the package on your phone for testing.
c) You can also upload the APK file to AppGallery Connect by clicking Upload next to Compile. Select a sign-in type, fill in the relevant information, and click Confirm.
2.2 Releasing your app to an Android platform
a) In the Build… panel, choose Android for Platform, connect a phone to your computer, and click Play to install the APK file to your phone.
b) You can also open the project in the \build\jsb-link\frameworks\runtime-src\proj.android-studio directory in Android Studio.
3. Testing the Crash Service
Usually, app crashes are not common. You can manually trigger a crash and test the Crash service by calling the AGConnectCrash.testIt method of the Crash SDK and then checking whether the crash data is reported in AppGallery Connect.
In this example, a test button CrashTest is created. You can click the button to trigger a crash. The API is defined as follows:
testIt(): void
Sample code:
huawei.agc.crash.CrashService.testIt();
4. Viewing a Crash Report
4.1 Viewing crash statistics
a) Package and run your app. Tap CrashTest to trigger a crash. Exit the app and launch it again.
b) In AppGallery Connect, click My projects.
c) Find your project from the project list and click your app on the project card.
d) Go to Quality > Crash. On the Crash page, click the Statistics tab and select Last hour to view crash statistics of your app.
4.2 Viewing crash stack details
Click the crash name to go to the crash details page. Click the Stack tab. The possible causes of the crash are displayed, helping you analyze the crash.
4.3 Obtaining a readable crash report
a) When ProGuard or DexGuard overrides class names, fields, and methods in code with unreadable code during building, you can obtain a de-obfuscation crash report from the obfuscation mapping file.
b) Find the obfuscation mapping file in the following directory in Android Studio and download the file.
c) On the Mapping file tab page in AppGallery Connect, click Upload.
d) It is found that the data is restored.
Summary
1. It is simple to integrate the Crash SDK into a Cocos-based app. You just need to create an app and enable HUAWEI Analytics and Crash.
2. If it is your first time integrating the SDK, you can use a demo app for testing.
3. In addition to Crash, some other Huawei services have started to support Cocos-based apps.
For more details, please check:
1. Cocos official documentation:
https://docs.cocos.com/creator/manual/en/cocos-service/agc-crash.html
2. HUAWEI AppGallery Connect Crash documentation:
https://developer.huawei.com/consum...Gallery-connect-Guides/agc-crash-introduction
3. HUAWEI AppGallery Connect Crash codelab:
https://github.com/AppGalleryConnect/agc-crash-codelab-java
4. Cocos Creator Integrates with AppGallery Connect APM — Releasing a Cocos-based App:
https://forums.developer.huawei.com/forumPortal/en/topic/0202382127496450426?fid=0101187876626530001
if you have any question, please refer to stackoverflow.

Integrating HUAWEI In-App Purchases Using Unity

Huawei's In-App Purchases (IAP) service allows you to offer in-app purchases and facilitates in-app payment. Users can purchase a variety of virtual products, including consumables and non-consumables.
1.1 Version Change History​
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
1.1.1 Version Dependencies​l The SDK of the latest version can be used only on devices running HMS Core (APK) 4.0.0.300 or later. If a user is using a device without HMS Core (APK) 4.0.0.300 or later, the user will be directed to install it when it is called by your app. User devices need to run EMUI 3.0 or later or Android 4.4 or later (API level 19 or later). The Unity version must be 2018.4.25 or later.
1.2 Preparations​1.2.1 Importing Unity Assets​1. Open Asset Store in Unity.
Go to Window > Asset Store in Unity.
2. Search for and import the Unity Distribution Portal (UDP) asset in Asset Store. For information about UDP, please visit https://docs.unity3d.com/Packages/[email protected]/manual/index.html.
1.2.2 App Development​Configure product information based on the sample, and then use the sample for test.
1.2.2.1 Uploading Your Project to UDP​1. Go to Window > Unity Distribution Portal > Settings in Unity and click Go to the Services Window.
2. Select an organization.
3. linked your project to a UDP client
Go to Window > Unity Distribution Portal > Settings > Inspector in Unity and click Generate new UDP client.
4. Set Game Title and UDP Sandbox Test Accounts.
1.2.2.2 Configuring Product Information in Your Unity Project​Go to Window > Unity Distribution Portal > Settings > Inspector > IAP Catalog.
After product information is configured, click Push to synchronize the information to UDP.
1.2.2.3 Creating an App and Configuring Product Information in AppGallery Connect​1.2.2.3.1 Creating an App​Create an app by following instructions in Creating an AppGallery Connect Project and Adding an App to the Project. The package name of the game for AppGalleryKit must end with .HUAWEI or .huawei. Otherwise, the game will be rejected.
1.2.2.3.2 Configuring Product Information​1. Sign in to AppGallery Connect and click My projects. Select your project, enable In-App Purchases, and obtain the public key.
2. Sign in to AppGallery Connect and click My apps.
3. Click an app from the app list to add a product.
1. Go to Operate > Products > Product Management and click Add Product.
2. Configure product information, which must be the same as that configured in Unity.
3. Activate the product.
1.2.2.4 Configuring the Unity Project Package Name​Go to Edit > Project Settings > Player, click the Android icon, and go to Other Settings.
Note: Ensure that the package name configured here must be the same as that in AppGallery Connect. All package names in AppGallery Connect must end with .huawei. If the package name in Unity does not end with .huawei, the UDP console will supplement it during repacking for name consistency.
1.2.2.5 Configuring Product Information in GameManager​1. Drag UDPSampleScene to the top.
2. Enter the configured product ID in GameManger.
3. Push all configurations.
1.2.3 Testing the APK​1. Go to File > Build Settings > Android in Unity and click Switch Platform.
1.1 Select UDP/Sample/UDPSampleScene.
1.2 Build the project. Save and install the APK.
2. Use the configured sandbox test account to initialize the APK.
2.1 Open the APK and tap Init.
2.2 Enter the configured sandbox account.
3. Initialize the sandbox test.
4. Tap the Buy button to test the product purchase function.
Verify that the sandbox test is complete.
1.2.4 Repacking the APK​1. Sign in to the UDP console.
2. Click the newly created game.
3. Edit the game information and then click Release.
4. Choose HUAWEI AppGallery.
5. Unity will automatically find the project info that has same package name in AGC, Set your IAP public Key manually
6. Choose HUAWEI AppGallery and click Publish.
7. The UDP console repacks your APK.
8. Download the repacked APK, which supports payment by IAP.
For more details, you can go to:
l Our official website
l Our Development Documentation page, to find the documents you need
l Reddit to join our developer discussion
l GitHub to download demos and sample codes
l Stack Overflow to solve any integration problems

Intermediate: How to integrate Huawei Auth Service in Unity

Introduction
In this article, we will cover how to verify Phone Number and Anonymous Account Login using Huawei Auth Service in Unity Project using Official Plugin (Huawei HMS Core App Services). AppGallery Connect provides a cloud-based Auth Service and SDKs to help you quickly build a secure and reliable user authentication system for your apps to verify user identity.
The AppGallery Connect Auth service supports multiple authentication methods and is seamlessly integrated with other server less services to secure user data based on simple rules that you have defined.
Key Functions​Using the AppGallery Auth Service SDK, you can integrate one or more of the following authentication methods into your app for achieving easy and efficient user registration and sign-in.
Self-owned account: Your self-owned account is used to support the access of your existing authentication system, so that your existing users can access other server less services in a secure manner.
Anonymous account: Anonymous accounts can be used to access your apps as visitors. The Auth service can assign user IDs to your app visitors, so that they can access other server less services in a secure manner. A visitor can be registered as a formal user and retain the original user ID to ensure service continuity.
Third-party accounts: AppGallery Connect allows user identity to be verified by third-party authentication services. The AppGallery Auth Service SDK supports the following accounts for user identity verification:
1. HUAWEI account
2. HUAWEI Game Service account
3. Phone number
4. Email account
5. WeChat account
6. Weibo account
Development Overview
You need to install Unity software and I assume that you have prior knowledge about the unity and C#.
Hardware Requirements
A computer (desktop or laptop) running Windows 10.
A Huawei phone (with the USB cable), which is used for debugging.
Software Requirements
Java JDK installation package.
Unity software installed.
Visual Studio/Code installed.
HMS Core (APK) 4.X or later.
Follows the steps.
1. Create Unity Project.
Open Unity Hub.
Click NEW, select 3D, Project Name and Location.
Click CREATE, as follows
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2. Click Asset Store, search Huawei HMS Core App Services and click Import, as follows.
3. Once import is successful, verify directory in Assets > Huawei HMS Core App Services path, as follows.
4. Choose Edit > Project Settings > Player and edit the required options in Publishing Settings, as follows.
5. Generate a SHA-256 certificate fingerprint.
To generating SHA-256 certificate fingerprint use below command
keytool -list -v -keystore D:\Unity\projects_unity\file_name.keystore -alias alias_name
6. Download agconnect-services.json and copy and paste to Assets > Plugins > Android, as follows.
7. Choose Project Settings > Player and update package name.
8. Open LauncherTemplate.gradle and add below line.
apply plugin: 'com.huawei.agconnect'
implementation 'com.huawei.agconnect:agconnect-auth:1.4.2.301'
implementation 'com.huawei.hms:base:5.2.0.300'
implementation 'com.huawei.hms:hwid:5.2.0.300'
9. Open AndroidManifest file and add below permissions.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
10. Open "baseProjectTemplate.gradle" and add lines, as follows.
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
maven {url 'https://developer.huawei.com/repo/'}
11. Open "mainTemplate.gradle" and add lines like shown below.
implementation 'com.huawei.agconnect:agconnect-auth:1.4.2.301'
implementation 'com.huawei.hms:base:5.2.0.300'
implementation 'com.huawei.hms:hwid:5.2.0.300'
12. Create MainActivity.java class inside Plugin > Android folder.
13. Follow the steps, as shown in image:
a. Assign Ads script to Canvas.
b. Select Button and add onclick event
c. Assign all button to button handler as per your requirements.
14. Onclick Button Handler you find your script HMSAuthService (As per your script name) and attach method as per below screen shot.
15. To build apk and run in device, choose File > Build Settings > Build for apk or Build and Run for run on connected device.
Result
1. Click on Anonymous Login, send OTP and Verify button you can see below results.
2. Find the details in AppGallery Connect, as follows.
Tips and Tricks
Always use the latest version of the library.
Add agconnect-services.json file without fail.
Add SHA-256 fingerprint without fail.
Make sure dependencies added in build files.
Make sure that you enabled the auth service in AG-Console.
Make sure that you enabled the Authentication mode in Auth Service.
Conclusion
In this article, we have learnt integration of Huawei Auth Service-AGC anonymous account login and mobile number verification through OTP in Unity Game development. Auth Service provides secure and reliable user authentication system to your application.
Thanks for reading the article, please do like and comment your queries or suggestions.
References
Unity Auth Service Manual
Auth Service
Checkout in forum

Categories

Resources