Add asset-based match index support for KSP library modules#391
Open
rossbacher wants to merge 7 commits into
Open
Add asset-based match index support for KSP library modules#391rossbacher wants to merge 7 commits into
rossbacher wants to merge 7 commits into
Conversation
rossbacher
commented
Jan 28, 2026
|
|
||
| # | ||
| # Copyright © 2015 the original authors. | ||
| # Copyright © 2015-2021 the original authors. |
Collaborator
Author
There was a problem hiding this comment.
Just updated gradlew to latest as of the used gradle version (9.2.1)
added 7 commits
April 20, 2026 15:28
This change adds an optional asset-based approach for storing the match index binary data when using KSP with the manifest-generation plugin. Instead of encoding the binary data as strings in the generated registry class, the match index is written as an Android asset file and loaded at runtime via AssetManager. Key changes: - Add shared constants in ManifestGeneration.kt for asset paths and KSP option - Generate AssetManager-based registry constructor when useAssetBasedMatchIndex=true - Add MergeDeepLinkAssetsTask and RelocateDeepLinkAssetsTask for Gradle plugin - Update ManifestGenerationPlugin to handle asset file relocation and merging - Add processor tests for asset-based and legacy string-based code generation - Update sample tests to use KspLibraryDeepLinkModuleRegistry with assets The asset-based approach provides: - Faster build times (no string chunking/encoding) - Faster app startup (direct binary loading, no string decoding) - Better APK compression (binary assets compress better than dex strings) Both modes (asset-based and string-based) are supported per-registry level.
- Share loadMatchIndexFromAsset helper via new Utils.RegistryUtils object
in the :deeplinkdispatch module so the processor no longer emits a
per-registry copy of the helper method.
- Fail the build (throw DeepLinkProcessorException) when the binary
match-index asset can't be written, instead of swallowing the
IOException as a diagnostic error.
- Replace runtime reflection for setting the KSP `deepLink.useAssetBasedMatchIndex`
arg with a typed call gated on pluginManager.withPlugin("com.google.devtools.ksp").
- Centralize KSP output paths in ManifestGeneration (kspResourcesDir,
kspGeneratedManifestPath, kspGeneratedAssetsDir) so the gradle plugin
and processor agree on one source of truth.
- Replace findByName-based task lookups in the plugin with
`tasks.matching { it.name == ... }.configureEach`, which is lazy and
tolerates KSP registering its variant-specific tasks after our
plugin code runs.
- Sample: use `gradle.projectsEvaluated` to wire the cross-project
copyLibraryAssetsForTest task (the producer is registered inside
a sibling project's AGP onVariants callback, which fires during
projectsEvaluated, not afterEvaluate), and use an exact consumer
task-name set so we don't end up depending on unrelated
lintVitalRelease tasks.
- Tests: add BaseDeepLinkProcessorTest stubs for RegistryUtils so KSP-
generated registries compile under the processor test classpath, and
add an end-to-end test that compiles the same deep links both ways
(string-encoded and asset-based) and asserts that the bytes of the
asset equal the bytes decoded from the generated string chunks.
ba52a88 to
864d4c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change adds an optional asset-based approach for storing the match index binary data when using KSP with the manifest-generation plugin. Instead of encoding the binary data as strings in the generated registry class, the match index is written as an Android asset file and loaded at runtime via AssetManager.
Key changes:
The asset-based approach provides:
Both modes (asset-based and string-based) are supported per-registry level.
I did run benchmarks on this and in the registry creation (the important benchmark) the asset based approach is bout 20-25% faster, less than I had hoped but this also simplifies this significantly especially once we drop kapt support.