Skip to content

v2 OssLicensesMenuActivity: kotlin.Metadata is stripped from the published AAR, so the Kotlin companion API can't be used idiomatically (no named arguments, Companion unresolved) #442

Description

@yshrsmz

Describe the bug

The v2 API (com.google.android.gms.oss.licenses.v2.OssLicensesMenuActivity) is written in Kotlin and documented with Kotlin-style usage, but the published AAR has the kotlin.Metadata annotation stripped from its classes. As a result, the Kotlin compiler treats setTheme() / setActivityTitle() as plain Java static methods:

  • Named arguments fail to compile: Named arguments are prohibited for non-Kotlin functions.
  • OssLicensesMenuActivity.Companion.setTheme(...) fails with Unresolved reference 'setTheme'.

This looks like a follow-up to #364: in 17.4.0 the companion methods were stripped entirely by ProGuard ("it got stripped out by proguard and we missed it"). 17.5.0 restored the methods themselves, but the Kotlin metadata is still being stripped, so Kotlin consumers lose named arguments, parameter names, and companion resolution on a Kotlin-first API.

To Reproduce

  1. Add com.google.android.gms:play-services-oss-licenses:17.5.1.
  2. Call the v2 API with named arguments:
OssLicensesMenuActivity.setTheme(
    lightColorScheme = myLightScheme,
    darkColorScheme = myDarkScheme,
    typography = myTypography,
)
  1. Compilation fails:
e: Named arguments are prohibited for non-Kotlin functions.
e: No parameter with name 'lightColorScheme' found.
e: No value passed for parameter 'p0'.
  1. Verify the cause in the published artifact — no kotlin.Metadata runtime annotation is present:
$ javap -v -classpath classes.jar com.google.android.gms.oss.licenses.v2.OssLicensesMenuActivity | grep kotlin.Metadata
(no output; only @kotlin.jvm.JvmStatic remains as a runtime-invisible annotation)

Expected behavior

kotlin.Metadata (and @Metadata on the Companion) is kept for the public v2 API classes so Kotlin consumers can use named arguments and companion access as documented. For libraries with a Kotlin public API this typically means keeping the metadata for public API classes in the ProGuard configuration used to build the release artifact (see e.g. -keep class kotlin.Metadata guidance for Kotlin SDK authors).

Desktop (please complete the following information):

  • Gradle version: 9.4.1
  • Android Studio version: N/A (CLI build)
  • Kotlin version: 2.3.21
  • Android Gradle Plugin: 9.2.1
  • Plugin name and version: oss-licenses-plugin 0.12.0
  • Library dependency: play-services-oss-licenses 17.5.1

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions