Intermediate: How to Integrate APM Service in Unity Game Development - Huawei Developers

Introduction
Huawei AppGallery Connect provides Application Performance Management (APM) service provides app performance monitoring capabilities. You can view the analyse app performance data collected by APM in AG Console, this helps to understand the app performance quickly and accurately in real time to rectify app performance problems and continuously improve user experience.
{
"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"
}
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 1.7 or later.
Unity software installed.
Visual Studio/Code installed.
HMS Core (APK) 4.X or later.
Integration Preparations
1. Create a project in AppGallery Connect.
2. Create Unity project.
3. Huawei HMS AGC Services to project.
4. Download and save the configuration file.
Add the agconnect-services.json file following directory Assests > Plugins > Android
5. Add the following plugin and dependencies in LaucherTemplate.
Code:
apply plugin: 'com.huawei.agconnect'
apply plugin: 'com.huawei.agconnect.apms'
Code:
implementation 'com.huawei.agconnect:agconnect-core:1.4.2.301'
implementation 'com.huawei.agconnect:agconnect-apms:1.4.1.303'
6. Add dependencies in build script repositories and all project repositories and class path in BaseProjectTemplate.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agconnect-apms-plugin:1.4.1.303'
classpath 'com.huawei.agconnect:agcp:1.4.2.301'
7 Create Empty Game object rename to GameManager, UI canvas texts and button and assign onclick events to respective text and button as shown below.
8. Click to Build apk, choose File > Build settings > Build to Build and Run, choose File > Build settings > Build And Run.
GameManager.cs
C#:
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;
using HuaweiService.apm;
public class GameManager : MonoBehaviour
{
CustomTrace customTrace;
void Start()
{
customTrace = APMS.getInstance().createCustomTrace("testTrace");
}
public void onClickButton(){
customTrace.start();
Debug.Log ("Hello" + " world");
UnityEngine.Debug.Log("CustomTraceMeasureTest start");
customTrace.putMeasure("ProcessingTimes", 0);
for (int i = 0; i < 155; i++) {
customTrace.incrementMeasure("ProcessingTimes", 1);
}
long value = customTrace.getMeasure("ProcessingTimes");
Debug.Log("Measurename: ProcessingTimes, value: "+ value);
UnityEngine.Debug.Log("CustomTraceMeasureTest success");
}
}
Result
To view AppGallery Connect analysis choose Quality > APM
Tips and Tricks
Add agconnect-services.json file without fail.
Make sure dependencies added in build files.
Make sure that you that APM Service enabled.
Conclusion
In this article, we have learnt integration of Huawei Application Performance Management (APM) Service into Unity Game development using official plugin. Conclusion is APM helps us to rectify quickly and accurately app performance and continuously improve user experience.
Thank you so much for reading article, I hope this article helps you.
Reference
Unity Manual
Service Introduction official documentation
Checkout in forum

Related

Super Chat - A conversation starter application using HMS Nearby and HMS Location Kit

More information like this, you can visit HUAWEI Developer Forum​
This article is based on Nearby Chat. We will create a new application that provides the chat with nearby people without the internet with the help of Nearby Kit and we can share our current location in latitude and longitude.
We are going to integrate the following kits in this application.
1) Nearby Kit
2) Awareness Kit
3) Scan Kit
Prerequisite
1) Must have a Huawei Developer Account.
2) Must have a Huawei phone with HMS 4.0.0.300 or later.
3) Must have a laptop or desktop with Android Studio, JDK 1.8, SDK platform 26 and Gradle 4.6 installed.
Things Need To Be Done
1) Create a project in android studio.
2) Create a project in the Huawei AppGallery connect.
3) Enable Nearby, Awareness, and Scan kit setting in Manage APIs section.
4) Provide storage location.
5) After completing all the above points we need to download the agconnect-services.json from App Information Section. Copy and paste the Json file in the app folder of the android project.
6) Enter the maven url inside the repositories of buildscript and allprojects (project build.gradle file).
7) Add dependencies inside the app module and Sync Project.
8) Start development with kit integration inside the application.
9) Launch the application.
Create a project in Android Studio
Open your android studio and create a new project, Choose No Activity then click on Next
{
"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"
}
Provide your application name, package, and project location then click on Finish.
Create a project on AppGalleryConnect portal
1. Open AppGalleryConnect portal and choose My projects
2. Click on Add project and provide your project’s details
3. Provide your project name and click Ok
Provide storage location
Navigate to General Information then provide Data Storage location.
Enable Nearby, Awareness, and Scan kit setting in Manage APIs section
Navigate to Manage APIs and enable APIs which require by application
After completing all the above points we need to download the agconnect-services.json
Navigate to General information then download the agconnect-services.json file
Add agconnect-services.json file into your project
Enter the maven url inside the repositories of buildscript and allprojects (project build.gradle file)
Add maven url and add following AppGalleryConnect class path.
Code:
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Add dependencies inside the app module and Sync Project
Add the following dependencies for kit specific in app module based gradle file
Code:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Awareness Kit
implementation 'com.huawei.hms:awareness:1.0.6.300'
//Nearby Kit
implementation 'com.huawei.hms:nearby:4.0.4.300'
//Scan Kit
implementation "com.huawei.hms:scan:1.2.0.301"
}
Start development with kit integration inside the application
We have created the following package inside the project
Awareness
We have handled all the operations in this package which is related to awareness kit. We have created LocationAwarenessActivity which implements location-awareness api.
getLocation() method provides accurate latitude and longitude.
Code:
private void getLocation() {
Awareness.getCaptureClient(this).getLocation()
.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(LocationResponse locationResponse) {
Location location = locationResponse.getLocation();
Utils.setHomeLatitude(location.getLatitude());
Utils.setHomeLongitude(location.getLongitude());
location_details_capture.setText("Capture Your Location
Longitude:" + location.getLongitude()
+ "
Latitude:" + location.getLatitude());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
location_details_capture.setText("Failed to get the location.");
}
});
}
This is not the end. For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201327967934830047&fid=0101188387844930001
Can we share media files also?

Coding-free Integration of AppGallery Connect Crash into an Android App

According to Huawei official document, AppGallery Connect Crash is a lightweight crash analysis service, in which Huawei provides a Crash SDK that can be quickly integrated into your app, without the need for coding. The SDK integrated into your app can automatically collect crash data and report the data to AppGallery Connect when your app crashes, helping you understand the version quality of your app, quickly locate the causes of crashes, and evaluate the impact scope of crashes.
In other words, Huawei provides an SDK. You can view the crash information of your app as long as you integrate it. No code is required. Isn't it great? Let's see how it works.
Creating Your Project and App
First, you need to create a project in AppGallery Connect and add an app to it. For details, see the AppGallery Connect documentation.
Enabling HUAWEI Analytics
The Crash service uses capabilities of HUAWEI Analytics when reporting crash events. Therefore, you must enable HUAWEI Analytics before integrating the Crash SDK. For details, please refer to the AppGallery Connect documentation.
Integrating SDKs
If you are using Android Studio, you need to integrate the Crash SDK into your Android Studio project before development.
1. Sign in to AppGallery Connect and click My projects.
2. Find the project you created from the project list, and click the app for integration on the project card.
3. Go to Project Settings > General information, and click agconnect-services.json under App information to download the configuration file.
{
"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"
}
4. Copy the agconnect-services.json file to the app's root directory of your Android Studio project.
5. Open the build.gradle file in the root directory of your Android Studio project, and configure the Maven repository address and AppGallery Connect plug-in address.
HTML:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
HTML:
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
6. Integrate the latest versions of the Analytics SDK and Crash SDK.
HTML:
dependencies {
implementation 'com.huawei.hms:hianalytics:5.0.4.200'
implementation 'com.huawei.agconnect:agconnect-crash:1.4.1.300'
}
7. Click Sync Now to synchronize the configuration.
Testing the Crash Service
You can create a test button CrashTest in your demo project, and call the testIt method provided by AppGallery Connect to trigger a crash.
The sample code for creating the button is as follows:
HTML:
<Button
android:id="@+id/btn0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize= "22dp"
android:textAllCaps="false"
android:text="CrashTest" />
The sample code for a tapping event is as follows:
HTML:
Button btn_crash0 = findViewById(R.id.btn0);
btn_crash0.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View view) {
AGConnectCrash.getInstance().testIt(MainActivity.this);
}
});
Package and run your app, and tap the CrashTest button to trigger a crash.
Viewing a Crash Report
You can view the details of the crash that you just triggered in AppGallery Connect.
1. Sign in to AppGallery Connect, go to My projects, and click your app.
2. Go to Quality > Crash. On the Crash page, click the Statistics tab, and view crash statistics of your app. The crash information is displayed 1 or 2 minutes after you run your app.
3. Click the Problems tab, and view the crash of your app. For example, in the following figure, java.lang.NullPointerException is the null pointer issue triggered during the test.
Click the crash to view its details. The possible causes of the crash are displayed, as shown in the following figure, helping you analyze the crash.
Summary:
1. It is easy to integrate the Crash service. During testing, you can either write code yourself, or use the testIt method provided by AppGallery Connect.
2. Crash reports are available in only 1 or 2 minutes.
3. All you need to write is just a few lines of code during testing. The service integration for app release is coding-free.
4. The Crash service also provides features including monitoring NDK crash reports, restoring obfuscated reports, and generating custom reports.
For more details, check:
HUAWEI AppGallery Connect Crash documentation: https://developer.huawei.com/consum...Gallery-connect-Guides/agc-crash-introduction
Huawei AGC Crash codelab:
https://developer.huawei.com/consumer/en/codelab/CrashService/index.html#0
Crash service supports to track Run time expectation data.
sujith.e said:
Crash service supports to track Run time expectation data.
Click to expand...
Click to collapse
yes, it begins to supports to track Runtime exception from 1.4.2.300 SDK version in November 20.

How Can I Quickly Integrate Cloud Functions of AppGallery Connect into My Cocos-based App?

1. Environment
SDK Version:agconnect-storage:1.3.0.300
Platform:Cocos Creator
Device:HUAWEI P40 Pro
AppGallery Connect:
https://developer.huawei.com/consumer/en/service/josp/agc/index.html
2. Enabling and Configuring Cloud Functions in AppGallery Connect
Note: Currently, Cloud Functions is still under beta state. To use the service, you need to send an email for application. For details, check:
https://developer.huawei.com/consum...allery-connect-Guides/agc-cloudfunction-apply
1. Create an app first and add it to a project, or select an app from the project list on the My projects page in AppGallery Connect.
Under the project, go to Build > Cloud Functions, and click Enable now.
2. Create a function based on the description in the following codelab.
https://developer.huawei.com/consumer/en/codelab/CloudFunctions/index.html#4
3. Create an HTTP trigger and save the suffix of the value of Trigger URL in the Details area as the trigger identifier of future client requests.
{
"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"
}
3. Integrating the Cloud Functions SDK in Cocos Creator
1. Integrate the SDK.
Official documentation:
https://docs.cocos.com/creator/manual/en/cocos-service/agc-applinking.html
1. On the Service panel of Cocos Creator, find Cloud Functions. Currently, the Cloud Functions SDK supports only the Android platform.
2. Before integrating a service, you need to associate the service with an app. Click Association. In the dialog box that is displayed, click Create. The Cocos console is displayed.
3. On the Cocos console, create a game.
4. Go back to Cocos Creator and create, refresh, or select an association.
5. Return to the Cloud Functions page, and enable the service.
2. Download the JSON file.
1. Go to Project settings in AppGallery Connect and download the latest agconnect-services.json file.
2. Save the downloaded agconnect-services.json file to the settings directory in your Cocos project.
4. Configuring the UI Layout
Configure buttons for triggering a cloud function, obtaining the timeout interval, and setting the timeout interval separately.
5. Cloud Functions Development
1. Initialize Cloud Functions in the start block.
Code:
start () {
this._func = huawei.agc.func.funcService;
},
2. Call Cloud Functions with input parameters.
Code:
callWithParam:function() {
this._func.wrap("testcodelab-$latest").call((err, data) => {
if (err !== null) {
console.log("Cloud Function", `error: ${JSON.stringify(err)}`);
}
console.log("Cloud Function", `result: ${JSON.stringify(data)}`);
}, {
year: "2020",
}
);
},
3. Call Cloud Functions without input parameters.
JavaScript:
callWithoutParam:function() {
this._func.wrap("testcodelab-$latest").call((err, data) => {
if (err !== null) {
console.log("Cloud Function", `error: ${JSON.stringify(err)}`);
}
console.log("Cloud Function", `result: ${JSON.stringify(data)}`);
});
},
4. Obtain and set the timeout interval of a function.
JavaScript:
setTime:function() {
this._func.wrap("testcodelab-$latest").setTimeout(100,3);
console.log("Cloud Function", `setTime: ` + 100);
},
getTime:function() {
let currTime = this._func.wrap("testcodelab-$latest").getTimeout();
console.log("Cloud Function", `currTime: ` + currTime);
},
6. Packaging and Testing
In Cocos Creator, go to Project > Build…, package an Android app, and install it to your device. To verify the functions, click the buttons from top to bottom.
If the following information is displayed in JavaScript logs, the integration is successful.
7. Summary
Cloud Functions allows you to keep all functions and related code on the cloud side. You only need to call the wrap.call method to trigger the functions, which reduces the code amount and package size of your APK package.
For more details, please check:
Cloud Functions development guide:
https://developer.huawei.com/consum...connect-Guides/agc-cloudfunction-introduction
Cocos documentation:
https://docs.cocos.com/creator/manual/en/cocos-service/agc-cloudfunc.html

Integrating Cloud Functions in a Flutter application

Cloud Functions enables serverless computing through Function as a Service (FaaS) capabilities to simplify app development and O&M. This helps you implement functions more simply and build service capabilities more quickly. The following describes how to integrate Huawei’s AppGallery Connect Cloud Function service in Flutter.
We will create a basic new project as an example but of course, you could make use of a project you already have that's using flutter!
Project Setup​Install the Flutter environment.​Download the Flutter SDK package and decompress the package to any directory.
{
"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"
}
Download the Flutter and Dart plugins in Android Studio.
Enable Huawei Cloud Functions​Create an Android app in AppGallery Connect and enable Cloud Functions for it as detailed in this guide.
Now we can go ahead and create a cloud function as you require it to use this guide to help understand what can be done.
Once you are happy with your function (in this instance it might just be as simple as returning a hello world statement for testing) you can go ahead and create a HTTP trigger that will trigger the function.
Create Flutter Project​Next create your flutter project in android studio (or open your existing project if you already have one!).
Download your agconnect-services.json file from the AppGallery Connect console and add it to your project under the ‘app’ directory
Within the project-level build.gradle file make sure to include the Huawei maven repo and add the agcp package as a dependency.
Code:
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.huawei.agconnect:agcp:1.6.2.300'
}
}
Next in your app level build.gradle apply the agconnect plugin as so:
Code:
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
Then in your pubspec.yaml file add the Cloud Function SDK dependency.
Code:
dependencies:
flutter:
sdk: flutter
agconnect_cloudfunctions: 1.2.0+300
Call the Cloud function​The below code is an example of how you can call a simple cloud function and get the result returned.
Code:
FunctionCallable functionCallable = FunctionCallable("test-\$latest");
Map<String, dynamic> parameters = <String, dynamic>{
'year': _functionTextController.text
};
FunctionResult functionResult = await functionCallable.call(parameters);
Where test-\$latest is the HTTP trigger identifier.
https://devwithzachary.medium.com/?...-------------------post_sidebar--------------
Good Article
Thanks for sharing!!!
Do we need any special permission for cloud function.
Thanks for sharing!

Integration of Push kit in Unity based game

Introduction​
Push notifications offers a great way to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application. These messages can be sent at any time and even if your app is not running at that time. To achieve this you need to follow steps.
Huawei Push Kit is a messaging service developed by Huawei for developers to send messages to apps on users’ device in real time. Push Kit supports two types of messages: notification messages and data messages, which we will cover both in this tutorial. You can send notifications and data messages to your users from your server using the Push Kit APIs or directly from the AppGallery Push Kit Console.
Things required
1. Unity Engine must be installed in the system.
2. Huawei phone or cloud debugging.
3. Visual Studio 2019
4. Android SDK & NDK
Steps to integrate
1. Sign In and Create or Choose a project on AppGallery Connect portal.
{
"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. Navigate to Project settings and download the configuration file.
3. Enable Push Kit from Manage APIs section.
4. Click Agree the Push service Agreement.
5. Select Data storage location.
6. Click Enable now Push notification.
7. Send Notification from the console.
8. Enter all the required details and click on Submit.
Game Development
1. Create a new game in Unity.
2. Now add game components and let us start game development.
3. Download HMS Unity Plugin from below site.
https://github.com/EvilMindDevs/hms-unity-plugin/releases
4. Open Unity Engine and import the downloaded HMS Plugin.
Choose Assets > Import Package> Custom Package
5. Choose Huawei > App Gallery.
6. Provide the AppId and other details from agconnect-service.json file and click configure Manifest.
7. Create Huawei Push Kit based scripts.
C#:
using UnityEngine;
namespace HuaweiHms{
public class IPushServiceListener:AndroidJavaProxy{
public IPushServiceListener():base("com.unity.hms.push.IPushService"){}
public virtual void onMessageReceived(RemoteMessage arg0) {
}
public void onMessageReceived(AndroidJavaObject arg0) {
onMessageReceived(HmsUtil.GetHmsBase<RemoteMessage>(arg0));
}
public virtual void onMessageSent(string arg0) {
}
public virtual void onNewToken(string arg0) {
}
public virtual void onSendError(string arg0, BaseException arg1) {
}
public void onSendError(string arg0, AndroidJavaObject arg1) {
onSendError(arg0,HmsUtil.GetHmsBase<BaseException>(arg1));
}
public virtual void onTokenError(BaseException arg0) {
}
public void onTokenError(AndroidJavaObject arg0) {
onTokenError(HmsUtil.GetHmsBase<BaseException>(arg0));
}
}
}
Result​
Tips and Tricks​
1. HMS plugin v1.2.0.
2. Make sure that you have installed HMS Core.
3. The Push Kit server allows a maximum of 1,000 tokens for sending messages at a time.
4. If exceed more than 1k it need to be sent batch wise.
Conclusion​
In this article, we have learnt what is push service, how to integrate in Unity based game. And also we have learnt that how to send notification from Huawei console to device.
References​
Unity Push kit

Categories

Resources