Include open source notices

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 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 pluginManagement of your project settings, do the following:

  1. Include the Google Maven repository .
  2. Resolve the oss-licenses plugin in the PluginManagement .

The following code snippet shows these steps:

Kotlin DSL

settings.gradle.kts

 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.10.6" 
 ) 
  
 } 
  
 } 
  
 } 
 } 

Groovy DSL

build.gradle

 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.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

app/build.gradle.kts

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

Groovy DSL

app/build.gradle

 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 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

 implementation 
 ( 
 "com.google.android.gms:play-services-oss-licenses:17.2.2" 
 ) 

Groovy DSL

build.gradle

 implementation 
  
 'com.google.android.gms:play-services-oss-licenses:17.2.2' 

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 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

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.

Design a Mobile Site
View Site in Mobile | Classic
Share by: