The Android SDK is a Kotlin library for Android apps. It fetches your workspace's published face lenses and screen effects with an API key, checks every file, keeps each version on the phone, and draws them in your app. It follows the same format and drawing rules as the studio's live preview and the iOS SDK, so it draws what your designers see in the editor.
The current version is 0.4.0. It is published as a Maven package, with a sample app, at github.com/Ingevora/mirage-android.
Add the repository to settings.gradle.kts. No account or token is needed:
settings.gradle.kts
dependencyResolutionManagement { repositories { google() mavenCentral() maven("https://ingevora.github.io/mirage-android/maven") { content { includeGroup("com.ingevora") } } } }
and the library to your app's build.gradle.kts:
build.gradle.kts
dependencies { implementation("com.ingevora:mirage:0.4.0") }
The library brings the INTERNET permission and its own shrinking rules; there is nothing else to declare. It finds faces with Google's ML Kit, using the model bundled in the app, so it needs no Google Play services on the phone. ML Kit adds about 12 MiB, uncompressed, to the app on a 64-bit ARM phone.
INTERNET
Make one client for the app, with the app's API key, and keep it, for example in your Application.
Application
val mirage = MirageClient(applicationContext, MirageClient.Configuration(apiKey = "mk_…")) // Prefetch what the app will show, so it starts without waiting. mirage.prefetchEffect("7c1e9a2b-4d3f-4a6e-8b5c-2f9d0e1a3b4c") { result -> if (result is MirageResult.Failure) showRetry(result.error) }
cancel()
suspendCancellableCoroutine
prefetchLens
prefetchEffect
version
// One player per screen that shows effects; keep it in a ViewModel, so effects run on across a rotation. val player = MirageEffectPlayer(mirage) // An overlay above the activity's content. It passes every touch through. val overlay = MirageEffectOverlay.show(activity, player) // In a layout: addView(MirageEffectView(context, player)) above the content. // Jetpack Compose: AndroidView(factory = { MirageEffectView(it, player) }, modifier = Modifier.fillMaxSize()) player.play("7c1e9a2b-4d3f-4a6e-8b5c-2f9d0e1a3b4c") player.onEnd = { playback -> if (playback.state == MiragePlayback.State.Ended(MiragePlayback.Ending.Finished)) { // the effect finished } }
close()
player.cue(effectId)
player.play(cue)
// One player per camera screen; keep it in a ViewModel and close() it when done. val lens = MirageLensPlayer(mirage) lens.attach("3f2b8c1e-6d4a-4f7e-9b2c-8a1d5e6f7a90") // stored at once, else downloaded // On your camera thread, for every frame (here CameraX's ImageAnalysis): send it, and use the frame that comes back. val drawn = lens.process( MirageFrame.of(image), imageProxy.imageInfo.timestamp, MirageFrame.Orientation.fromRotationDegrees(imageProxy.imageInfo.rotationDegrees), ) send(drawn) drawn.close() // The self-view. container.addView(MirageLensPreviewView(context, lens))
process
YUV_420_888
RGBA_8888
MirageFrame.yuv
process(frame, time, orientation, face)
state
Your app sends its own event names, and the triggers that listen for them run:
player.fire("order.placed") // every running screen effect lens.fire("round.start") // the attached face lens
A name the format doesn't allow is ignored. See Triggers and your events.
A failure is a MirageError:
MirageError
InvalidAPIKey
401
ProductDisabled
403
NotFound
404
Unavailable
429
5xx
EngineTooOld
UnsupportedFormat
InvalidPackage
A later version may add cases to the SDK's sealed types, so a when over one keeps an else branch:
when
else
when (error) { MirageError.InvalidAPIKey -> showKeyHelp() MirageError.NotFound -> showMissing() else -> showRetry() }
See Errors and limits.
cacheDir/com.ingevora.mirage
clearCache
freshness
source
CacheFallback
The SDK plays published face lenses and screen effects. In a debuggable build of your app, it also plays drafts from Test on your phone: lens.attachTestLink(link) for a face lens and player.playTestLink(link) for a screen effect, and the view marks them "TEST — draft". A release build of your app refuses test links.
lens.attachTestLink(link)
player.playTestLink(link)
sample/ in the repository shows the whole integration in three short files. Clone the repository, open it in Android Studio and run sample on an Android phone. Paste your API key, then the id of a published face lens or screen effect.
sample/
sample