Google Play services sometimes includes, or depends 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 notices of libraries used in their apps. One of these tools is a Gradle plugin that collects license terms from included libraries, as declared in their POM files, and creates an activity that can be used to display these terms. Learn more about how the tool finds and packages license information.
Add the Gradle plugin
In your root-level build file, do the following:
- Include the Google Maven repository.
- Add the
oss-licenses
plugin to your dependencies.
The following code snippet shows these steps:
Kotlin DSL
buildscript { repositories { ... google() // maven { url("https://maven.google.com") } for Gradle <= 3 } dependencies { ... classpath("com.google.android.gms:oss-licenses-plugin:0.10.6") } }
Groovy DSL
buildscript { repositories { ... google() // maven { url "https://maven.google.com" } for Gradle <= 3 } dependencies { ... classpath 'com.google.android.gms:oss-licenses-plugin:0.10.6' } }
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
plugins { id("com.android.application") id("com.google.android.gms.oss-licenses-plugin") }
Groovy DSL
plugins { id 'com.android.application' id 'com.google.android.gms.oss-licenses-plugin' }
You can view the code for this plugin on GitHub.
Add the library to your app
In the dependencies
section of your app-level build file, add a dependency on theoss-licenses
library:
Kotlin DSL
implementation("com.google.android.gms:play-services-oss-licenses:17.1.0")
Groovy DSL
implementation 'com.google.android.gms:play-services-oss-licenses:17.1.0'
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
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity ... // When the user selects an option to see the licenses: startActivity(Intent(this, OssLicensesMenuActivity::class.java))
Java
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity; ... // When the user selects an option to see the licenses: startActivity(new Intent(this, OssLicensesMenuActivity.class));
When launched, this activity display a list of open source libraries that are compiled into your app, including the libraries that are a part of Google Play services, as shown in figure 1. Users can tap on the name of a library to view additional license information for that library.
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()
,
as shown in the following code snippet:
Kotlin
OssLicensesMenuActivity.setActivityTitle(getString(R.string.custom_license_title))
Java
OssLicensesMenuActivity.setActivityTitle(getString(R.string.custom_license_title));
Apply a theme to the activity
You can apply a theme to the activity 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:
<application android:theme="@style/AppTheme" ...> <activity android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity" android:theme="@style/AppTheme" /> <activity android:name="com.google.android.gms.oss.licenses.OssLicensesActivity" 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>
element and embeds the link and title of each license in an Android asset that's
included with your app.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-11-21 UTC.