bazelbuild / bazelbuild/rules_android

java_resource_extractor exclusion lists miss entries that AGP strips by default (KMP klib metadata, root LICENSE/NOTICE files)

Open Beginner friendly
#535 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
203
Forks
95
PR merge metrics
No merged PRs in 30d

Description

src/tools/java_resource_extractor/resource_extractor.py filters out well-known junk from java resources, but its exclusion lists miss a few things that AGP's default packaging rules strip, so they end up in the final APK:

- `.knm` files (Kotlin/Native klib metadata)
- `.kotlin_metadata` files
- `linkdata/` directories (e.g. `commonMain/.../linkdata/*`)
- root-level `LICENSE.txt` / `NOTICE.txt` from library jars (the META-INF copies are already covered by the meta-inf directory exclusion)

The klib metadata is only consumed by the Kotlin compiler when compiling against a library; nothing reads it at runtime, so in an APK it's dead weight. In the Gradle world it's common to exclude it via packaging options on top of AGP's defaults. With a KMP-heavy dependency tree (kotlinx-*, androidx KMP artifacts) it adds up — on our app stripping all of the above saved ~0.45 MiB uncompressed (~0.24 MiB compressed).

This deliberately does not touch `META-INF/*.kotlin_module`, which kotlin-reflect needs at runtime.

Patch: https://github.com/Dolfik1/rules_android/commit/ead968493476d45059224949ec2536755b1a8aab

Happy to send this as a PR.

Contributor guide

Open the contributing guide

Research direction

Start in src/tools/java_resource_extractor/resource_extractor.py by reading the existing resource exclusion lists and comparing them with the entries named in the issue. Update the filtering so .knm, .kotlin_metadata, linkdata/, and root LICENSE.txt/NOTICE.txt are excluded, while META-INF/*.kotlin_module remains included; verify the resulting APK contents.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin, python
Domain
build-system, mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.