Skip to content

OssLicensesMenuActivity crashes with Resources$NotFoundException: Resource ID #0x0 in release builds with resource shrinking (AGP 9) #460

Description

@chibatching

Describe the bug

OssLicensesMenuActivity (v1) crashes on launch in release builds that have resource shrinking enabled (isMinifyEnabled = true + isShrinkResources = true) under AGP 9. Debug builds are unaffected because resource shrinking is off there.

Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.ResourcesImpl.getValue (ResourcesImpl.java:300)
    at android.content.res.Resources.loadXmlResourceParser (Resources.java:2575)
    at android.content.res.Resources.getLayout (Resources.java:1289)
    at android.view.LayoutInflater.inflate (LayoutInflater.java:460)
    at com.google.android.gms.oss.licenses.zzp.onCreateView (com.google.android.gms:play-services-oss-licenses@@17.5.1:2)
    ...
    at androidx.fragment.app.FragmentActivity.onStart (FragmentActivity.java:348)

It reproduced for every user who opened the licenses screen in our Play Store build, across device models and OS versions.

To Reproduce

  1. Apply com.google.android.gms.oss-licenses-plugin 0.13.0 and com.google.android.gms:play-services-oss-licenses:17.5.1 to an app module.
  2. In the release build type set isMinifyEnabled = true and isShrinkResources = true.
  3. Build with AGP 9 (./gradlew assembleRelease) and install the release APK.
  4. startActivity(Intent(context, OssLicensesMenuActivity::class.java)).
  5. The activity crashes on start with the stack trace above.

Expected behavior

OssLicensesMenuActivity works in release builds with resource shrinking enabled, without the app having to know about the library's internal resource names.

Screenshots

N/A (crash on launch).

Desktop (please complete the following information):

  • Gradle version: 9.7.0 (AGP 9.3.1)
  • Android Studio version: Quail 3 | 2026.1.3 Patch 1
  • Plugin name and version: OSS Licenses plugin 0.13.0 / play-services-oss-licenses 17.5.1

Additional context

Our analysis of the 17.5.1 AAR points at resource shrinking removing layouts that the library only looks up dynamically.

The Fragment that OssLicensesMenuActivity hosts (zzp in 17.5.1) resolves its layout by name through Resources.getIdentifier() in onCreateView, rather than through an R constant:

inflater.inflate(
    resources.getIdentifier("license_menu_fragment", "layout", packageName),
    container, false)

Since nothing references R.layout.license_menu_fragment as a constant, the shrinker drops the layout, getIdentifier() returns 0, and LayoutInflater.inflate(0, ...) throws Resource ID #0x0.

This looks like a regression tied to AGP 9. The same app built with AGP 8.x and android.r8.optimizedResourceShrinking=true kept license_menu_fragment in the APK. After upgrading to AGP 9, where optimized resource shrinking is the standard pipeline, it is dropped — the getIdentifier() string-constant heuristic that safe mode relies on no longer marks these resources as reachable.

As a workaround we added a keep file to our own app module:

<!-- app/src/main/res/raw/<your_package>_keep.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="
        @layout/license_menu_fragment,
        @layout/libraries_social_licenses_license,
        @id/license,
        @id/license_list" />

With that in place resources.txt reports both layouts as reachable from keep xml file and the licenses screen works again.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions