<br />

Google Play services SDKs sometimes include, or depend upon, open source
libraries. To comply with the license requirements of open source libraries, you
as a developer are responsible for appropriately displaying the notices for the
open source libraries that your app uses.

Google Play services includes a set of tools designed to give developers an
easier way to express the open source software (OSS) notices of libraries used
in their apps. The `oss-licenses-plugin` and the Google Play services
oss-licenses SDK collect license terms from included libraries, as declared in
their POM files, and create an
[activity](https://developer.android.com/guide/components/activities/intro-activities)
that can be used to display these terms. Learn more about
[how the tool finds and packages license information](https://developers.google.com/android/guides/opensource.md.txt#how-licenses-are-determined).

## Add the Gradle plugin

In your `pluginManagement` of your project settings, do the following:

1. Include the [Google Maven repository](https://developer.android.com/studio/build/dependencies#google-maven).
2. Resolve the `oss-licenses` plugin in the `PluginManagement`.

The following code snippet shows these steps:

### Kotlin DSL

settings.gradle.kts

```kotlin
pluginManagement {
  repositories {
    ...
    google()
  }
  resolutionStrategy {
    eachPlugin {
      if (requested.id.id == "com.google.android.gms.oss-licenses-plugin") {
        useModule("com.google.android.gms:oss-licenses-plugin:0.13.0")
      }
    }
  }
}
```

### Groovy DSL

build.gradle

```groovy
pluginManagement {
  repositories {
    ...
    google()
  }
  resolutionStrategy {
    eachPlugin {
      if (requested.id.id == "com.google.android.gms.oss-licenses-plugin") {
        useModule("com.google.android.gms:oss-licenses-plugin:0.13.0")
      }
    }
  }
}
```

In your app-level build file, apply the plugin by adding the following line
under the existing declaration of the `com.android.application` plugin at the
top of the file:

### Kotlin DSL

app/build.gradle.kts

```kotlin
plugins {
    id("com.android.application")
    id("com.google.android.gms.oss-licenses-plugin")
}
```

### Groovy DSL

app/build.gradle

```groovy
plugins {
    id 'com.android.application'
    id 'com.google.android.gms.oss-licenses-plugin'
}
```

You can
[view the code](https://github.com/google/play-services-plugins)
for this plugin on GitHub.

## Add the `play-services-oss-licenses` library to your app

In the `dependencies` section of your app-level build file, add a dependency on
the `play-services-oss-licenses` library:

### Kotlin DSL

build.gradle.kts

```kotlin
implementation("com.google.android.gms:play-services-oss-licenses:17.5.3")
```

### Groovy DSL

build.gradle

```groovy
implementation 'com.google.android.gms:play-services-oss-licenses:17.5.3'
```

## Display license information

When your app builds, the Gradle plugin processes the licenses and adds them to
your app's resources. To easily display the license, you can launch an activity
that's provided by the `play-services-oss-licenses` library at an appropriate
point in your app, as shown in the following code snippet:

### Kotlin

```kotlin
import com.google.android.gms.oss.licenses.v2.OssLicensesMenuActivity
...

// When the user selects an option to see the licenses:
startActivity(Intent(this, OssLicensesMenuActivity::class.java))
```

### Java

```java
import com.google.android.gms.oss.licenses.v2.OssLicensesMenuActivity;
...

// When the user selects an option to see the licenses:
startActivity(new Intent(this, OssLicensesMenuActivity.class));
```

When the activity is launched, it displays a list of open source libraries that
are compiled into your app, including libraries used by the app, as shown in
figure 1. Users can tap on the name of a library to view additional license
information for that library.

![List view with each element containing the name of an open source library](https://developers.google.com/static/android/guides/images/oss-licenses.svg)

**Figure 1.** The licenses menu activity shows a selectable list of open source
libraries that an app uses.

### Set the activity title

By default, the displayed activity has the title "Open source licenses". You can
customize the title of the activity by calling
[`setActivityTitle()`](https://developers.google.com/android/reference/com/google/android/gms/oss/licenses/v2/OssLicensesMenuActivity.md.txt#setActivityTitle(kotlin.String)),
as shown in the following code snippet:

### Kotlin

```kotlin
OssLicensesMenuActivity.setActivityTitle(getString(R.string.custom_license_title))
```

### Java

```java
OssLicensesMenuActivity.setActivityTitle(getString(R.string.custom_license_title));
```

### Apply a theme to the activity

There are different ways to apply a theme to the `OssLicensesMenuActivity`,
depending on whether your app uses Material 3 or XML-based themes.

#### Apps that use Material 3

For apps that use Material 3, you can call the
[`setTheme()`](https://developers.google.com/android/reference/com/google/android/gms/oss/licenses/v2/OssLicensesMenuActivity.md.txt#setTheme(androidx.compose.material3.ColorScheme,androidx.compose.material3.ColorScheme,androidx.compose.material3.Typography))
method to apply a custom theme to the activity, as shown in the following code
snippet:

### Kotlin

```kotlin
import com.google.android.gms.oss.licenses.v2.OssLicensesMenuActivity
...

OssLicensesMenuActivity.setTheme(lightColorScheme, darkColorScheme, typography)
startActivity(Intent(this, OssLicensesMenuActivity::class.java))
```

### Java

```java
import com.google.android.gms.oss.licenses.v2.OssLicensesMenuActivity;
...

OssLicensesMenuActivity.setTheme(lightColorScheme, darkColorScheme, typography);
startActivity(new Intent(this, OssLicensesMenuActivity.class));
```

#### Apps that use XML themes

For apps that use XML themes, you can apply a theme to the activity in the
manifest to match the theme used in your app's other activities. To do so,
include the open source license activity in an `<activity>` element within your
app's manifest file, as shown in the following code snippet:

```xml
<application android:theme="@style/AppTheme" ...>
    <activity
        android:name="com.google.android.gms.oss.licenses.v2.OssLicensesMenuActivity"
        tools:replace="android:theme"
        android:theme="@style/AppTheme" />
</application>
```

## How the list of licenses is determined

At compile time, the Gradle plugin scans the POM dependencies of your app's
project. When a Maven POM exists for a direct dependency of the app, the plugin
processes each [`<licenses>`](https://maven.apache.org/pom.html#Licenses)
element and embeds the link and title of each license in an Android asset that's
included with your app.

> [!NOTE]
> **Note:** The list of licenses also includes the full license text of any library that is depended upon by the transitive closure of Google Play services libraries used by the app. This means that the list includes any open source libraries that are used to create the Google Play services libraries that are compiled into your app.