Last updated on: May 27, 2023
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 by Google.
Contents
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.5'
}
}
// ...
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.xml)
<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 questions, please feel free to leave a comment below