How to list Third-Party Dependencies Licenses in your Android app

In this tutorial, I’m going to show you how to implement a method that shows the licenses of the third-party dependencies automatically, using the OSS Licenses plugin made from Google.

Adding the OSS Licenses plugin

Go to the root-level build.gradle of your project and add the following line inside the dependencies { … }

buildscript { // ... dependencies { // ... classpath 'com.google.android.gms:oss-licenses-plugin:0.10.2' } } // ...
Code language: Kotlin (kotlin)

Next, go to the app-level build.gradle of your app, add the following library, and apply the plugin at the bottom:

dependencies { // ... implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0' // ... } apply plugin: 'com.google.android.gms.oss-licenses-plugin'
Code language: Kotlin (kotlin)

Showing dependencies licenses

You can show the licenses of your dependencies by calling the following line inside a listener.

// ... license_btn.setOnClickListener { startActivity(Intent(this, OssLicensesMenuActivity::class.java)) } // ...
Code language: Kotlin (kotlin)

Customizing the OSS Licenses Activity

Changing Title

Change the title of the OSS Licenses Menu Activity by adding the following line before you call the activity:

license_btn.setOnClickListener { OssLicensesMenuActivity.setActivityTitle("Third-Party Licenses") // ... }
Code language: Swift (swift)

Changing Theme

Use a different theme for OSS Licenses Menu Activity and OSS Licenses Activity by adding the following in your AndroidManifestl.xml (manifests > AndroidManifest.xmll)

<activity android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity" android:theme="@style/MyCustomTheme" /> <activity android:name="com.google.android.gms.oss.licenses.OssLicensesActivity" android:theme="@style/MyCustomTheme" />
Code language: HTML, XML (xml)
You can find the final project here

If you have any questionsplease feel free to leave a comment below

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments