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.
  1. In Unity, go to Window → Package Manager

    package manager
  2. In the window that pops up, click the plus (+) icon in the status bar.

  3. Click Add package from disk…​ to bring up a file browser

    add package
  4. Navigate to the root of the com.strivr.strivrsdk folder that you downloaded.

  5. Open the package.json file in the root folder.

    package file

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.

  1. In Unity, go to Strivr → Settings

    strivr settings
  2. In the window that pops up, in the Project Settings tab, click Log in and follow steps to log in with Google.

    strivr project settings
  3. 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.

    sdk project dropdown

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.

  1. From the Edit menu, select Project Settings.

    unity project settings
  2. For Unity 2020 and newer:

    1. Under PlayerAndroid tab → Publishing SettingsBuild, 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.

      project settings unity2020
    2. Add the maven repository to baseProjectTemplate.gradle and add the dependency to mainTemplate.gradle.

      1. In baseProjectTemplate.gradle, copy and paste the maven repository under both the allprojects/buildscript/repositories and allprojects/repositories sections.

        base project template
        baseProjectTemplate.gradle in Unity 2020 or newer
      2. In mainTemplate.gradle, copy and paste the dependency under dependencies.

        unity 2020 maintemplate gradle
        mainTemplate.gradle in Unity 2020
    3. 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
    4. Open gradleTemplate.properties and copy and paste the following line under the ADDITIONAL_PROPERTIES section, then save the file.

      android.useAndroidX=true
      gradle template prop file
      gradleTemplate.properties
  3. For Unity 2019:

    1. Under PlayerAndroid tab → Publishing SettingsBuild, use the checkbox to select Custom Gradle Template.

      custom gradle
      Project Settings in Unity 2019
    2. Edit mainTemplate.gradle to add both the maven repository and dependency.

      1. 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'
        }
      2. 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'
        unity 2019 dependencies
        mainTemplate.gradle in Unity 2019
    3. 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 PackagesStrivr SDKRuntimePrefabs. Drag the StrivrSDK prefab into what will be the first scene in the build.