Google packages for Unity are distributed in two different formats:

- [Asset packages](https://developers.google.com/unity/instructions#install-unitypackage):
  - Have a `.unitypackage` extension.
  - Install to your project's `Assets` directory.
  - Can be imported in Unity 5 and up.
  - Generally include dependent packages.
- [Unity Package Manager (UPM) packages](https://developers.google.com/unity/instructions#install-tgz):
  - Have a `.tgz` extension.
  - Install to your project's `Packages` directory.
  - Can be imported in Unity 2018.4 and up.
  - Reference dependent packages which need to be installed separately.

The [Packages](https://developers.google.com/unity/packages) page contains the latest `.unitypackage` files
for all available packages, and `.tgz` files for some of the packages.

The [Archive](https://developers.google.com/unity/archive) page contains `.unitypackage` and `.tgz` files for
all package versions.

Below you can find instructions on how to install both types of packages, along
with migration instructions to transition from on type to the other.

Once you're familiar with these installation options, be sure to refer to
additional [product-specific instructions](https://developers.google.com/unity/instructions#product-instuctions) for Firebase.

## Importing packages using OpenUPM

You can add external packages to your Unity project using the OpenUPM
registry. OpenUPM hosts many useful plugins and SDKs, such as the Google Play
Integrity plugin, which helps protect your app from fraud and abuse.

Here's how to add, for example, the Google Play Integrity plugin using OpenUPM.

### OpenUPM-CLI

If you have the [OpenUPM CLI](https://github.com/openupm/openupm-cli#installation)
installed you can install the OpenUPM registry with the following command:

    openupm add com.google.play.integrity

### OpenUPM

1. Open the [package manager settings](https://docs.unity3d.com/Manual/class-PackageManager.html)
   by selecting the Unity menu option
   **Edit \> Project Settings \> Package Manager**.

2. Add OpenUPM as a scoped registry to the Package Manager window:

       Name: package.openupm.com
       URL: https://package.openupm.com
       Scopes: com.google.external-dependency-manager
        com.google.play.common
        com.google.play.core
        com.google.play.integrity

3. Open the [package manager menu](https://docs.unity3d.com/Manual/upm-ui-install.html) by selecting the Unity
   menu option **Window \> Package Manager**.

4. Set the manager scope drop-down to select **My Registries**.

   ![](https://developers.google.com/static/admob/images/unity_upm_registry.png)
5. Select the **Google Play Integrity plugin for Unity** package from the
   package list and press **Install**.

## Importing Asset packages with `.unitypackage` files

Import the `.unitypackage` file by selecting the Unity menu option
`Assets > Import package > Custom Package` and importing all items.
This adds the package contents to your project under the Assets
directory.

> [!NOTE]
> **Note:** If you have already installed the package using Unity's Package Manager window, uninstall the old version of the package before importing the new one. See [below](https://developers.google.com/unity/instructions#migrate) for instructions.

## Importing UPM packages with `.tgz` files (2018.4+)

Import `.tgz` files into your project using one of the following methods:

### manifest.json

1. Create a new folder next to your project's `Packages` folder and name it `GooglePackages`.
2. Place the `.tgz` files into that folder.
3. Use a text editor to open `Packages/manifest.json` under your Unity project folder.
4. Add an entry for each package you want to install, mapping the package name
   to the location on disk, relative to the `Packages/manifest.json` file. Be sure to append `file:` to the `.tgz` file path. For
   example, if you were installing `com.google.firebase.storage` and its
   dependencies, your manifest.json would look like this:

       {
         "dependencies": {
           "com.google.external-dependency-manager": "file:../GooglePackages/com.google.external-dependency-manager-1.2.164.tgz",
           "com.google.firebase.app": "file:../GooglePackages/com.google.firebase.app-7.1.0.tgz",
           "com.google.firebase.auth": "file:../GooglePackages/com.google.firebase.auth-7.1.0.tgz",
           "com.google.firebase.storage": "file:../GooglePackages/com.google.firebase.storage-7.1.0.tgz",
           // com.unity package entries...
         }
       }

5. Save the manifest.json file.

6. When Unity regains focus it will reload the manifest.json and import the newly added packages.

Some older versions of Unity do not support `.tgz` files in the manifest.json.
In this case, you should:

1. Uncompress the `.tgz` files.
2. Place the extracted folder in the `GooglePackages` folder.
3. Edit your manifest.json to use the path to the extracted folder, instead
   of the `.tgz` file, like so:

       {
         "dependencies": {
           "com.google.external-dependency-manager": "file:../GooglePackages/com.google.external-dependency-manager-1.2.164",
           "com.google.firebase.app": "file:../GooglePackages/com.google.firebase.app-7.1.0",
           "com.google.firebase.auth": "file:../GooglePackages/com.google.firebase.auth-7.1.0",
           "com.google.firebase.storage": "file:../GooglePackages/com.google.firebase.storage-7.1.0",
           // com.unity package entries...
         }
       }

### Package Manager UI

1. Open Unity's Package Manager window.
2. Click the `+` icon in the top-left corner of the Package Manager window and
   select `Add package from tarball` to open the file browser.

   ![Screenshot of Unity Package Manager Window with the](https://developers.google.com/static/unity/images/upm-add-tarball-screenshot.png)
3. Select the desired tarball in the file browser.

Some older versions of Unity do not support adding tarballs directly.
In this case, you will need to:

1. Uncompress the `.tgz` file.
2. Click the `+` icon in the top-left corner of the Package Manager
   window and select `Add package from disk` to open the file browser.

   ![Screenshot of Unity Package Manager Window with the](https://developers.google.com/static/unity/images/upm-add-from-disk-screenshot.png)

   > [!NOTE]
   > **Note:** Unity 2018 places the `+` icon on the bottom-left corner of the package list pane.

3. Select the extracted folder in the file browser.

Make sure to also import the `.tgz` files for the package's dependencies,
which you can find listed on the [archive page](https://developers.google.com/unity/archive) under the
desired package's section.

For example, if you were installing `com.google.firebase.storage`, you would
install these `.tgz` files in the following order:

1. External Dependency Manager (`com.google.external-dependency-manager`)
2. Firebase Core (`com.google.firebase.app`)
3. Firebase Auth (`com.google.firebase.auth`)
4. Firebase Storage (`com.google.firebase.storage`)

If you would prefer to add all the `.tgz` files at once, without worrying
about the order, you can follow the instructions in the
[manifest.json tab](https://developers.google.com/unity/instructions#open-close-manifest).

> [!NOTE]
> **Note:** If you have already installed the package with a `.unitypackage` file, be sure to delete that version of the package before adding a new one. See [below](https://developers.google.com/unity/instructions#unitypackage-to-upm) for instructions.

### Version control

If you're using version control software to manage your project files, we
recommend adding the relevant `.tgz` files to version control. You can manually
edit your project's `manifest.json` (see
[above instructions](https://developers.google.com/unity/instructions#open-close-manifest)) and reference local `.tgz` files using
relative paths.

If you're using git, we recommend
[Git Large File Storage (LFS)](https://git-lfs.github.com/)
for managing large `.tgz` files.

## Migrating from UPM packages to Asset packages

In some cases, you might want to switch from using
[Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui.html)
to manage Google packages, to installing packages under the Assets folder.

Make sure all Google packages are removed from Unity Package Manager using
either of the following methods:

### Package Manager UI

1. Open Unity's Package Manager window.
2. Select `In Project` in the dropdown on the upper left.

   ![Screenshot of Unity Package Manager Window with the](https://developers.google.com/static/unity/images/upm-in-project-screenshot.png)
3. Type `com.google` into the search bar to filter for Google packages.

   ![Screenshot of Unity Package Manager Window with](https://developers.google.com/static/unity/images/upm-search-screenshot.png)
4. Click on each package name then click `Remove`.

### manifest.json

1. Use a text editor to open `Packages/manifest.json` under your Unity project folder.
2. Check if there are any packages from Google under "dependencies". The package name should start with "com.google", for instance "com.google.firebase.app".
3. Delete those lines and save the json file.
4. When Unity regains focus, it will reload the `manifest.json` file and remove the deleted packages.

Once you have uninstalled those packages from Unity Package Manager, you can
download and import replacement `.unitypackage` files from the [archive
page](https://developers.google.com/unity/archive).

## Migrating from Asset packages to UPM packages

In some cases, you might want to switch from installing products under the
Assets tree to installing and tracking products with Unity Package Manager.

If you're not sure which installation method you're using, in the Unity UI,
check whether the desired Google packages appears in the Project tab, under
Assets.

To migrate to UPM packages:

1. Make sure all Google package are removed from the Assets folder.

   - To uninstall Firebase packages follow [these instructions](https://firebase.google.com/docs/unity/setup-alternative#alternative_migrate_to_upm).
   - To uninstall Play Plugins for Unity, delete the `GooglePlayPlugins` folder under `Assets`.
2. Install packages using Unity Package Manager, as described
   [above](https://developers.google.com/unity/instructions#install-tgz).

## Product-specific Migration Instructions

See [here](https://firebase.google.com/docs/unity/setup-alternative) for Firebase instructions.