Search code examples
gradleandroid-gradle-pluginaar

How to make license information available to Google OSS license plugin for an Android aar library?


I'm using the OSS license plugin (note: I have to use version 0.9.5 because of a bug)

As far as I know, there is no "official" support for entering license information in Gradle (even though this could possibly be included in Gradle metadata in a later version of the specification) but by deploying the AAR artefact with a pom file it is possible to declare a license.

According to the official documentation this should be enough:

How licenses are determined

The Gradle plugin scans the POM dependencies of the project at compile time. When a Maven POM exists for a direct dependency of the app, the plugin processes the element and embeds the link and title of each license in an Android asset in the final app APK.

Source: https://developers.google.com/android/guides/opensource#how_licenses_are_determined

I have done so for my aar library. Here is a snippet of the resulting pom.xml file deployed in the Nexus repository:

<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0.0</version>
<packaging>aar</packaging>
<licenses>
   <license>
      <name>Proprietary license</name>
      <url>https://someurl</url>
   </license>
</licenses>

Unfortunately, OssLicensesMenuActivity still won't list my dependency. My declaration looks like this:

api('com.mycompany:my-artifact@aar') {
    transitive = true
}

I suppose that the plugin is meant for Open Source licenses but I don't see how this can matter technically.

Question: How can I package an Android library with a specified license that will show up in OssLicensesMenuActivity for apps that depend on this library?


Solution

  • I was able to make this work. The trick is to make the dependency available through a Maven2 repository. If the pom.xml file is available with the license tag, then this will be displayed in the OssLicensesMenuActivity.

    There is still, to my knowledge, no "native" Gradle way of specifying the license however.