[Huawei Developers] lokeshsuryan:
Location Kit combines the GNSS, Wi-Fi, and base station location functionalities into your app to build up global positioning capabilities, allowing you to provide flexible location-based services for global users. Currently, it provides three main capabilities: fused location, activity identification, and geofence. You can call one or more of these capabilities as needed.

1.1 Version Change History​

1.1.1 Version Dependencies and Restrictions​

For details, please refer to the development guide.

1.2 Preparations​

1.2.1 Importing Unity Assets​

1.2.2 Generating .gradle Files​

1. Enable project gradle.

Go to Edit > Project Settings > Player in Unity, click the Android icon, and go to Publishing Settings > Build.

Enable Custom Main Manifest.

Enable Custom Main Gradle Template.

Enable Custom Launcher Gradle Template.

Enable Custom Base Gradle Template.

View attachment 5257813

View attachment 5257815

2. Generate a signature.

You can use an existing keystore file or create a new one to sign your app.

Go to Edit > Project Settings > Player in Unity, click the Android icon, and go to Publishing Settings > Keystore Manager.

Then, go to Keystore... > Create New.

View attachment 5257817

Enter the password when you open Unity. Otherwise, you cannot build the APK.

1.2.3 Configuring .gradle Files and the AndroidManifest.xml File​

1. Configure the baseProjectTemplate.gradle file.

<p style="line-height: 1.5em;">allprojects {
buildscript {
repositories {**ARTIFACTORYREPOSITORY**
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
// If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity.
// For the Gradle version preinstalled with Unity, please visit https://docs.unity3d.com/Manual/android-gradle-overview.html.
// For the official Gradle and Android Gradle Plugin compatibility table, please visit https://developer.android.com/studio/releases/gradle-plugin#updating-gradle.
// To specify a custom Gradle version in Unity, go do Preferences > External Tools, deselect Gradle Installed with Unity (recommended) and specify a path to a custom Gradle version.
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
**BUILD_SCRIPT_DEPS**
}
}
repositories {**ARTIFACTORYREPOSITORY**
google()
jcenter()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
maven { url 'https://developer.huawei.com/repo/' }
}
}</p>

2. Configure the launcherTemplate.gradle file.

<p style="line-height: 1.5em;">dependencies {
implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
implementation 'com.huawei.hms:base:4.0.1.300'
implementation 'com.huawei.hms:hwid:4.0.1.300'
implementation 'com.huawei.hms:location:5.0.0.302'
...
}
3. Configure the mainTemplate.gradle file.
dependencies {
...
implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
implementation 'com.huawei.hms:base:4.0.1.300'
...
**DEPS**}</p>

4. Configure the AndroidManiest.xml file.

<p style="line-height: 1.5em;"><?xml version="1.0" encoding="utf-8"?>
<!-- Generated by Unity. Remove this comment to prevent overwriting when exporting again. -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="com.huawei.hms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application>
<activity android:name="com.hms.hms_analytic_activity.HmsAnalyticActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="unity.cn"
android:scheme="https" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<receiver
android:name="com.unity.hms.location.LocationBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.huawei.hmssample.location.LocationBroadcastReceiver.ACTION_PROCESS_LOCATION" />
</intent-filter>
</receiver>
<receiver
android:name="com.unity.hms.location.GeoFenceBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.huawei.hmssample.geofence.GeoFenceBroadcastReceiver.ACTION_PROCESS_LOCATION" />
</intent-filter>
</receiver>
</application>
</manifest></p>

1.2.4 Adding the agconnect-services.json File​

1. Create an app by following instructions in Creating an AppGallery Connect Project and Adding an App to the Project.

Run keytool -list -v -keystore C:\TestApp.keyStore to generate the SHA-256 certificate fingerprint based on the keystore file of the app. Then, configure the fingerprint in AppGallery Connect.

View attachment 5257829

2. Download the agconnect-services.json file and place it in the Assets/Plugins/Android directory of your Unity project.

View attachment 5257831

1.2.5 Enabling Location Kit​

1. Sign in to AppGallery Connect.

2. Go to My projects > Project settings > Manage APIs, and enable the Location Kit API.

View attachment 5257833

1.3 Official Asset Sample Code​

For details, please visit the following link:

App Services(HMS) | Hms Core App Services | 1.2.0

docs.unity.cn

1.3.1 Testing the APK​

1.3.1.1 Testing the APK​

1. Generate the APK.

Go to File > Build Settings > Android, click Switch Platform and then Build And Run.

View attachment 5257835

2. Create a geofence in AppGallery Connect. For details, please visit the following link:

Create a geofence in AppGallery Connect

Read full article in forum