Skip to content

krlan2789/Unity-Background-Location

Repository files navigation

Setting Up Background Location in Unity with LAN LiveLocation Plugin

This guide walks you through setting up background location functionality in Unity using the LAN LiveLocation plugin. Follow the steps below to ensure a smooth integration.


Supported Platforms

  • Android OS: Tested on Android 10 and Android 14 devices.
  • iOS: Coming soon.

Requirements and Installation

Step 1: Install External Dependency Manager for Unity

To manage dependencies, you need to install the External Dependency Manager for Unity:

Step 2: Install the Live Location Plugin

Add the Live Location plugin to your Unity project:

  1. Open the Package Manager window.
  2. Click the Add button in the toolbar.
  3. Select Add package from git URL.
  4. Paste the following URL: https://github.com/krlan2789/Unity-LAN-LiveLocation-Plugin.git.

Step 3: Set Minimum API Level

Ensure the minimum API level is set to API Level 26.

Step 4: Verify Build Settings

Check and configure the required build settings.

Step 5: Update AndroidManifest.xml

Add the following permissions to Assets/Plugins/Android/AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.LAN.BackgroundLocation" xmlns:tools="http://schemas.android.com/tools">

     <!-- Required permissions -->
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" android:minSdkVersion="29" />
     <!-- Optional permissions -->
     <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

     <application>
          <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector">
          ...
     </application>
</manifest>

Step 6: Update launcherTemplate.gradle

Insert the following script into Assets\Plugins\Android\launcherTemplate.gradle:

android {
     ...
     packagingOptions {
          pickFirst('META-INF/okio.kotlin_module')
          pickFirst('META-INF/kotlinx_coroutines_core.version')
     }
}

Step 7: Update mainTemplate.gradle

Insert the following script into Assets\Plugins\Android\mainTemplate.gradle:

android {
     ...
     packagingOptions {
          pickFirst('META-INF/okio.kotlin_module')
          pickFirst('META-INF/kotlinx_coroutines_core.version')
     }
}

Step 8: Update gradleTemplate.properties

Insert the following script into Assets\Plugins\Android\gradleTemplate.properties:

android.enableJetifier=true
android.suppressUnsupportedCompileSdk=34

Common Errors and Troubleshooting

Custom Gradle Properties Template :

Custom Launcher Gradle and Custom Main Gradle :


By following these steps, you can successfully integrate background location functionality into your Unity project using the LAN LiveLocation plugin