google / google/play-services-plugins
OssLicensesMenuActivity crashes with Resources$NotFoundException: Resource ID #0x0 in release builds with resource shrinking (AGP 9)
- Dominant language
- Kotlin
- Stars
- 526
- Forks
- 167
- Avg merge
- 7d 21h
- Merged PRs (30d)
- 2
Description
**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:
```java
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:
```xml
```
With that in place `resources.txt` reports both layouts as `reachable from keep xml file` and the licenses screen works again.
Contributor guide
Research direction
Start by reproducing the crash with AGP 9 using ./gradlew assembleRelease, then inspect OssLicensesMenuActivity and the zzp.onCreateView path in the 17.5.1 AAR. Compare the generated resources.txt with the app's res/raw keep XML and verify that the release APK retains license_menu_fragment and libraries_social_licenses_license and that the licenses screen opens without crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100