Skip to content

Add memory options, TFLite migration, and Play services snippets for the litert-runtime skill - #1348

Open
john-rocky wants to merge 5 commits into
android:mainfrom
john-rocky:litert-runtime-skill-more-snippets
Open

john-rocky wants to merge 5 commits into
android:mainfrom
john-rocky:litert-runtime-skill-more-snippets

Conversation

@john-rocky

@john-rocky john-rocky commented Dec 1, 2026 •

Copy link
Copy Markdown

Adds Kotlin snippets for the parts of the litert-runtime skill that #1336's CompiledModel snippets don't cover: the memory options of Step 2, the migration from the legacy TFLite Interpreter, and LiteRT in Google Play services.

The two Play services regions, which create the Environment and load the model with it, are in ai. They need play-services-litert, which the skill says never to put in the same build variant as com.google.ai.edge.litert:litert, a dependency of ai: that variant's APK would carry both runtimes. So ai has play-services-litert as compileOnly, which keeps it out of the ai app: the two regions compile, but they can't run in that app. Their file, LiteRtPlayServicesSnippets.kt, also has copies of #1336's Classifier and MainViewModel, changed to use the Environment from Play services, so the file builds without #1336.

Apart from imports and formatting, one of the 12 regions differs from the skill's blocks at android/skills commit 7f7b2173. android_litert_runtime_skill_play_services_load has one more line, if (classifier != null) return@launch, after the Environment is awaited and before a Classifier is created. If another load call created a Classifier during that wait, the waiting coroutine stops at that line and creates no second one.

As suggested in the review of #1186, the imports and the dependency lines this PR adds have no region tags: the imports-only block of references/migration.md and the Gradle blocks stay in the skill.

ai gets the same litert and litert-gpu 2.4.1 lines as #1336, plus litert-support 2.4.1 for android_litert_runtime_skill_migration_support_image. My other pull requests, #1336 and #1340, add dependency lines in ai/build.gradle.kts and gradle/libs.versions.toml at some of the same places as this one. A plain merge of this branch with either of them conflicts in both files. After each merge, I'll update whichever of the three are still open.

Testing

  • With JDK 25, as in the build workflow, the build, spotlessCheck and extractSnippets tasks of ai succeed, and extractSnippets extracts the 12 regions.
  • After the Play services regions moved into ai, the 21 ai tests ported from MemoryOptionsTest and MigrationCodeTest in google-ai-edge/litert-samples passed on a Pixel 8a. The test code is not part of this pull request.

…the litert-runtime skill

The Play services code is in a new :ai:litert-play-services app module,
because the skill says never to put play-services-litert and
com.google.ai.edge.litert:litert in the same build variant.
@john-rocky
john-rocky requested review from a team as code owners December 1, 2026 21:19
@snippet-bot

snippet-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 12 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@kkuan2011 kkuan2011 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually prefer to avoid creating new modules when possible, can we add these snippets to the ai module instead like in this PR (#1186)?

This removes the :ai:litert-play-services module.

In ai, play-services-litert is compileOnly, so it stays out of the ai
app, which ships com.google.ai.edge.litert:litert.
@john-rocky

Copy link
Copy Markdown
Author

Yes, these snippets are now in the ai module, and the :ai:litert-play-services module is removed.

@kkuan2011 kkuan2011 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also get a teammate who's more familiar with the code to approve?

Comment thread ai/build.gradle.kts
implementation(libs.google.adk.core.android)
ksp(libs.google.adk.processor)
implementation(libs.mlkit.genai.prompt)
implementation(libs.litert)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit this list of dependencies is a little hard to read now, I would prefer if the whole list was grouped by implemention, testImpelmentation, etc.. and then alphabetized within those lists. But I don't want to cause a bigger diff than necessary on this file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep the current order here so the diff doesn't grow.

@john-rocky

Copy link
Copy Markdown
Author

@smilingday, could you review and approve this pull request, as @kkuan2011 asked above?

If you can, please also review and approve #1336 (the follow-up to your #1186) and #1340, which are waiting for approval too.

@john-rocky

Copy link
Copy Markdown
Author

@riggaroo @yrezgui, could one of you review this pull request along with #1336 and #1340, and approve them if they look good?

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants