Project Setup in Unity
Importing the Strivr SDK Unity package
In Unity, Import the Strivr SDK Unity Package into your project via UPM (Unity Package Manager).
Strivr SDK supports Unity versions from 2019.1.x to 2020.3 LTS. Android is the only supported platform. The minimum supported Android version is Android 4.1, "Jelly Bean", API level 16. |
-
In Unity, go to Window → Package Manager
-
In the window that pops up, click the plus (+) icon in the status bar.
-
Click Add package from disk… to bring up a file browser
-
Navigate to the root of the com.strivr.strivrsdk folder that you downloaded.
-
Open the package.json file in the root folder.
Linking the Unity project to a Strivr project
Once the package is installed, you must link your Unity project to a Strivr project before you can start tracking data.
-
In Unity, go to Strivr → Settings
-
In the window that pops up, in the Project Settings tab, click Log in and follow steps to log in with Google.
-
In Unity, return to Project Settings and, from the dropdown, choose the Strivr project to which you want to link the Unity project. You only need to select the project once; the Strivr project remains selected each time you open the project in Unity.
Adding Android dependencies to Unity project
First, you need to add the repository where the Android library is hosted. Then you’ll add the dependency itself. Where to add the repository and dependency depends on if you are using Unity 2020 or an older version. In both cases, you will need a file called mainTemplate.gradle. If you do not already have this file in your project, the file will be created during these steps.
-
From the Edit menu, select Project Settings.
-
For Unity 2020 and newer:
-
Under Player → Android tab → Publishing Settings → Build, use the checkboxes to select Custom Main Gradle Template, Custom Base Gradle Template, and Custom Gradle Properties Template.
This will automatically generate the mainTemplate.gradle file in the Assets/Plugins/Android directory. If they don’t already exist, selecting these options will automatically generate the files baseProjectTemplate.gradle and gradleTemplate.properties, respectively, in the Assets/Plugins/Android directory.
-
Add the maven repository to baseProjectTemplate.gradle and add the dependency to mainTemplate.gradle.
-
In baseProjectTemplate.gradle, copy and paste the maven repository under both the allprojects/buildscript/repositories and allprojects/repositories sections.
baseProjectTemplate.gradle in Unity 2020 or newer -
In mainTemplate.gradle, copy and paste the dependency under dependencies.
mainTemplate.gradle in Unity 2020
-
-
If it is present, remove the following comment at the top of mainTemplate.gradle and/or baseProjectTemplate.gradle:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
-
Open gradleTemplate.properties and copy and paste the following line under the ADDITIONAL_PROPERTIES section, then save the file.
android.useAndroidX=true
gradleTemplate.properties
-
-
For Unity 2019:
-
Under Player → Android tab → Publishing Settings → Build, use the checkbox to select Custom Gradle Template.
Project Settings in Unity 2019 -
Edit mainTemplate.gradle to add both the maven repository and dependency.
-
Copy and paste the following line under the repositories section under allprojects:
maven { url 'https://pkgs.dev.azure.com/strivr/SDK/_packaging/StrivrPublicFeed/maven/v1' }
-
Then copy and paste the following line under the dependencies section and save the file.
implementation 'com.strivr.strivr.sdk:strivr.sdk:1.0.22199.02'
mainTemplate.gradle in Unity 2019
-
-
If it is present, remove the following comment at the top of mainTemplate.gradle and/or baseProjectTemplate.gradle:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
-
Placing the Strivr SDK prefab
The StrivrSDK prefab needs to be placed in the first scene of the build only. |
The prefab has a DontDestroyOnLoad script on it, so the prefab will persist throughout scene progressions. If there were already scenes added to the Build Settings upon integration of the plugin, the prefab will already be in the first scene and the popup window will have alerted you which scene the prefab was placed into when you linked your account. If you have not yet set up the scenes in Build Settings, you will need to manually add the prefab to the proper scene. You can find the prefab in Packages → Strivr SDK → Runtime → Prefabs. Drag the StrivrSDK prefab into what will be the first scene in the build.