02Integration Guide

Integrate the player into iOS / Android / Web / Flutter / HarmonyOS

Installation steps, dynamic replacement snippets, and cleanup examples below build on each official repository README. Check the support matrix above before choosing a package.

SDK MATRIX

Multi-platform SDK versions & maintenance status

Several original SVGA repositories on GitHub are now archived (read-only), while Web Lite, HarmonyOS, and community Flutter continuations remain actively maintained. Verify compatibility before choosing a package.

PlatformPackage / RepoLatest ReleaseFormatsAudioUpstream StatusRecommended Path
iOSSVGAPlayer (CocoaPods)2.5.71.x & 2.0SupportedUpstream repo archived (read-only)Use 2.5.7 in production (includes entity-reuse mask fix)
AndroidSVGAPlayer-Android (JitPack)2.6.11.x & 2.0Supported (SVGASoundManager)Upstream repo archived (read-only)Pin 2.6.1 and configure ProGuard Wire/Proto keep rules
Web (Classic)svgaplayerweb (npm)2.3.21.x (needs JSZip) & 2.0Supported (needs howler.js + ID3)Upstream repo archived (read-only)Use only when SVGA 1.x or embedded audio is required
Web Litesvga (npm)2.1.12.0 onlyNot supportedActively maintainedDefault choice for mobile web, Vue 3, and React (< 18 KB gz)
Fluttersvgaplayer_flutter / flutter_svga2.2.0 (official)2.0 onlyPackage-dependentsvgaplayer_flutter archived; use flutter_svgaPrefer active community package flutter_svga on pub.dev for Dart 3+
HarmonyOS@tb-open/svga (OHPM)Active on OHPM2.0Check OHPM docsActively maintainedUse SvgaPlayerV2 and SvgaController on HarmonyOS NEXT
01

CocoaPods · Objective-C / Swift

iOS

Native CoreAnimation renderer that loads SVGA files from the app bundle or a remote server.

iOS 2.5.7 · Native CoreAnimation

Note: The official SVGAPlayer-iOS GitHub repository is archived read-only; the final CocoaPods tag is 2.5.7 (fixing mask loss when reusing VideoEntity). Swift projects work seamlessly via an Objective-C bridging header.

Install

Add the dependency to your Podfile, then run pod install.

Install
Ruby
target 'MyApp' do
  pod 'SVGAPlayer', '~> 2.5'
end

Usage

Create SVGAPlayer and SVGAParser, assign the parsed videoItem, and start the animation.

Usage
Objective-C
SVGAPlayer *player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.view addSubview:player];

SVGAParser *parser = [[SVGAParser alloc] init];
[parser parseWithNamed:@"posche" inBundle:nil completionBlock:^(SVGAVideoEntity *videoItem) {
    if (videoItem != nil) {
        player.videoItem = videoItem;
        [player startAnimation];
    }
} failureBlock:nil];

Swift Integration Example

After importing SVGAPlayer in your bridging header, parse and play animations asynchronously.

Swift Integration Example
Swift
let player = SVGAPlayer(frame: CGRect(x: 0, y: 0, width: 240, height: 240))
player.loops = 1
player.clearsAfterStop = true
view.addSubview(player)

let parser = SVGAParser()
parser.parse(withNamed: "posche", in: nil, completionBlock: { [weak player] videoItem in
    guard let item = videoItem else { return }
    player?.videoItem = item
    player?.startAnimation()
}, failureBlock: { error in
    print("SVGA parse failed:", error)
})

Dynamic Replacement (setImage / setAttributedText)

Replace avatar bitmaps or overlay localized labels on named imageKey sprites.

setImage / setText
Swift
if let avatar = UIImage(named: "user_avatar") {
    player.setImage(avatar, forKey: "avatar_slot")
}
let text = NSAttributedString(
    string: "VIP Lv.10",
    attributes: [
        .font: UIFont.boldSystemFont(ofSize: 22),
        .foregroundColor: UIColor.white
    ]
)
player.setAttributedText(text, forKey: "banner_text_slot")

Cache & Cell-Reuse Cleanup

Reset dynamic overrides and clear player references before reusing cells or tearing down views.

Lifecycle / Cache
Swift
player.stopAnimation()
player.clearDynamicObjects()
player.clear()
player.videoItem = nil

Notes

  • Use parseWithURL:completionBlock:failureBlock: to load animations from a remote server.
  • Dynamic images, text, hidden elements, and custom drawing are documented in the repository wiki.
02

Gradle · JitPack · Kotlin

Android

Native Android Canvas renderer that loads animations from assets or a remote server.

Android 2.6.1 · Native Canvas

Note: SVGAPlayer-Android is archived read-only on GitHub. Pin 2.6.1 via JitPack and keep Wire/Proto classes in ProGuard.

Install

Add the JitPack repository to the root build.gradle, then add the dependency to app/build.gradle.

Install
Gradle
// root build.gradle
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

// app/build.gradle
implementation 'com.github.svga:SVGAPlayer-Android:2.6.1'

Usage

Add SVGAImageView to your layout, point it at an animation, and enable autoplay.

Usage
XML
<com.opensource.svgaplayer.SVGAImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:source="posche.svga"
    app:autoPlay="true" />

Kotlin Programmatic Parsing

Initialize the shared parser once in Application.onCreate, then decode from assets or network URLs.

Kotlin Programmatic Parsing
Kotlin
// Application.onCreate()
SVGAParser.shareParser().init(this)

// Activity / Fragment
SVGAParser.shareParser().decodeFromAssets("posche.svga", object : SVGAParser.ParseCompletion {
    override fun onComplete(videoItem: SVGAVideoEntity) {
        svgaImageView.setVideoItem(videoItem)
        svgaImageView.startAnimation()
    }
    override fun onError() {
        // Fallback or error telemetry
    }
})

Dynamic Replacement (SVGADynamicEntity)

Bind dynamic bitmaps and styled TextPaint values onto matching imageKey layers.

setImage / setText
Kotlin
val dynamicEntity = SVGADynamicEntity()
dynamicEntity.setDynamicImage(avatarBitmap, "avatar_slot")

val textPaint = TextPaint().apply {
    color = Color.WHITE
    textSize = 28f
    isFakeBoldText = true
}
dynamicEntity.setDynamicText("VIP Lv.10", textPaint, "banner_text_slot")

svgaImageView.setImageDrawable(SVGADrawable(videoItem, dynamicEntity))
svgaImageView.startAnimation()

Audio, Cache & Lifecycle Cleanup

Enable clearsAfterDetached for RecyclerView safety and release audio resources on exit.

Lifecycle / Cache
Kotlin
svgaImageView.clearsAfterDetached = true
svgaImageView.clearsAfterStop = true
svgaImageView.stopAnimation(true)
svgaImageView.clear()
// Release 2.6.0+ audio sound pool when exiting screen
SVGASoundManager.release()

Notes

  • Call SVGAParser.shareParser().init(context) before using the shared parser.
  • Keep com.squareup.wire.** and com.opensource.svgaplayer.proto.** when minifying.
  • The README shows the legacy compile configuration; new projects should use implementation.
03

npm / CDN · JavaScript

Web

Full-featured web player with SVGA 1.x support (via JSZip), audio playback, and IE compatibility mode.

Web Classic 2.3.2 · Full Feature

Note: svgaplayerweb (SVGAPlayer-Web) is archived upstream, but remains required whenever you need SVGA 1.x support or embedded MP3 audio playback.

Install

Install from npm or load the CDN build directly.

Install
Shell
npm install svgaplayerweb --save

<!-- or load directly -->
<script src="https://cdn.jsdelivr.net/npm/svgaplayerweb@2.3.2/build/svga.min.js"></script>

Usage

Create a container, instantiate Player and Parser, then load and play the animation.

Usage
HTML
<div id="demoCanvas"></div>

<script>
  const player = new SVGA.Player('#demoCanvas');
  const parser = new SVGA.Parser('#demoCanvas');
  parser.load('rose.svga', (videoItem) => {
    player.setVideoItem(videoItem);
    player.startAnimation();
  });
</script>

SVGA 1.x & Audio Dependencies

Include JSZip for 1.x ZIP files and howler.js for ID3-prefixed audio tracks.

SVGA 1.x & Audio Dependencies
HTML
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/howler@2.2.4/dist/howler.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/svgaplayerweb@2.3.2/build/svga.min.js"></script>

Dynamic Replacement (setImage / setText)

Attach dynamic image URLs or canvas text before calling startAnimation().

setImage / setText
JavaScript
parser.load('gift.svga', (videoItem) => {
  player.setImage('https://example.com/avatar.png', 'avatar_slot')
  player.setText(
    { text: 'Welcome VIP', family: 'sans-serif', size: '24px', color: '#ffffff' },
    'banner_text_slot'
  )
  player.setVideoItem(videoItem)
  player.startAnimation()
})

Teardown & Memory Cleanup

Clear dynamic objects and canvas buffers on SPA route transitions.

Lifecycle / Cache
JavaScript
player.clearsAfterStop = true
player.stopAnimation()
player.clearDynamicObjects()
player.clear()

Notes

  • SVGA 1.x support requires JSZip; audio playback requires howler.js.
  • Use Web Lite when bundle size matters.
04

npm / CDN · TypeScript

Web Lite

Lightweight player for mobile web, under 60 KB (under 18 KB gzipped), with WebWorker parsing.

Web Lite 2.1.1 · Actively Maintained

Note: Recommended for modern web apps (< 18 KB gzipped), using WebWorker parsing and OffscreenCanvas/ImageBitmap. Supports SVGA 2.0 without audio.

Install

Install from npm or use the unpkg CDN build.

Install
Shell
npm i svga

<!-- or load directly -->
<script src="https://unpkg.com/svga/dist/index.min.js"></script>

Usage

Create a Parser, load the animation, mount it to a canvas, and start playback.

Usage
TypeScript
import { Parser, Player } from 'svga'

const parser = new Parser()
const svga = await parser.load('xx.svga')

const player = new Player(document.getElementById('canvas'))
await player.mount(svga)
player.start()

React / Vue 3 Safe Mount & Cleanup

Always destroy both player and parser on unmount to avoid leaking WebWorkers and image bitmaps.

React / Vue 3 Safe Mount & Cleanup
TypeScript
// React useEffect pattern (same cleanup applies in Vue 3 onBeforeUnmount)
useEffect(() => {
  const parser = new Parser()
  const player = new Player({ container: canvasRef.current!, loop: 0 })
  let disposed = false

  parser.load('/assets/gift.svga').then(async (svga) => {
    if (disposed) return
    await player.mount(svga)
    player.start()
  })

  return () => {
    disposed = true
    player.stop()
    player.clear()
    player.destroy()
    parser.destroy()
  }
}, [])

Dynamic Replacement (replaceElements)

Mutate parsed VideoEntity replacement maps before mounting onto the player.

setImage / setText
TypeScript
const svga = await parser.load('/assets/gift.svga')
const img = new Image()
img.crossOrigin = 'anonymous'
img.src = 'https://example.com/avatar.png'
await img.decode()

svga.replaceElements['avatar_slot'] = img
await player.mount(svga)
player.start()

IndexedDB Persistence & Frame Caching

Use the built-in DB helper and frame cache options to avoid re-downloading repeated gifts.

Lifecycle / Cache
TypeScript
import { DB, Parser, Player } from 'svga'

const db = new DB()
let svga = await db.find('gift_v2')
if (!svga) {
  svga = await parser.load('/assets/gift.svga')
  await db.insert('gift_v2', svga)
}
const player = new Player({
  container: document.getElementById('canvas') as HTMLCanvasElement,
  isCacheFrames: true,
  isUseIntersectionObserver: true
})
await player.mount(svga)
player.start()

Notes

  • Does not support the SVGA 1.x format or audio playback.
  • Supports Android 4.4+ and iOS 9+.
05

pub.dev · Dart

Flutter

Flutter implementation built on CustomPainter that loads animations from local assets or a remote server.

Flutter · Legacy 2.2.0 Archived / Use flutter_svga

Note: The original svgaplayer_flutter (2.2.0) repo is archived upstream. For Dart 3 null safety and recent Flutter releases, evaluate the active pub.dev community package flutter_svga.

Install

Add the dependency to pubspec.yaml.

Install
YAML
dependencies:
  svgaplayer_flutter: ^2.0.0

Usage

Use SVGASimpleImage for the simplest integration, or SVGAAnimationController for full playback control.

Usage
Dart
SVGASimpleImage(
  resUrl: 'https://github.com/svga/SVGA-Samples/blob/master/angel.svga?raw=true',
)

Modern Flutter Setup (flutter_svga)

Pair SVGAAnimationController with SingleTickerProviderStateMixin and always dispose the controller.

Modern Flutter Setup (flutter_svga)
Dart
// pubspec.yaml — check pub.dev/packages/flutter_svga for current version
// dependencies:
//   flutter_svga: ^latest

import 'package:flutter/material.dart';
import 'package:flutter_svga/flutter_svga.dart';

class SvgaBanner extends StatefulWidget {
  const SvgaBanner({super.key});
  @override
  State<SvgaBanner> createState() => _SvgaBannerState();
}

class _SvgaBannerState extends State<SvgaBanner> with SingleTickerProviderStateMixin {
  late final SVGAAnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = SVGAAnimationController(vsync: this);
    SVGAParser.shared.decodeFromAssets('assets/gift.svga').then((videoItem) {
      if (!mounted) return;
      _controller.videoItem = videoItem;
      _controller.repeat();
    });
  }

  @override
  Widget build(BuildContext context) => SVGAImage(_controller);

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}

Dynamic Replacement (dynamicItem)

Assign dynamic images or TextPainters on videoItem.dynamicItem before playback.

setImage / setText
Dart
videoItem.dynamicItem.setImageWithUrl('https://example.com/avatar.png', 'avatar_slot');
videoItem.dynamicItem.setText(
  TextPainter(
    text: const TextSpan(
      text: 'VIP Lv.10',
      style: TextStyle(color: Colors.white, fontSize: 22, fontWeight: FontWeight.bold),
    ),
  ),
  'banner_text_slot',
);

Dispose VideoEntity & Controller

Dispose unused MovieEntity / VideoEntity objects when switching gifts to free decoded textures.

Lifecycle / Cache
Dart
_controller.stop();
_controller.videoItem?.dispose();
_controller.dispose();

Notes

  • Supports the SVGA 2.0 format only.
  • Handle resource caching with a library such as dio and decode cached bytes with SVGAParser.
06

OHPM · ArkTS

HarmonyOS

SVGA player for HarmonyOS NEXT with declarative UI 1.0 and 2.0 components.

HarmonyOS NEXT · @tb-open/svga

Note: Actively maintained for HarmonyOS NEXT declarative UI 1.0 & 2.0 via OHPM.

Install

Install with OHPM.

Install
Shell
ohpm install @tb-open/svga

Usage

Initialize SVGA, create a controller, and render the animation with SvgaPlayerV2.

Usage
ArkTS
import { Svga, SvgaController, SvgaPlayerV2 } from '@tb-open/svga'

// AbilityStage.onCreate
Svga.init(this.context)

private controller: SvgaController = new SvgaController({
  loops: 3,
  fillMode: 'forwards',
  autoRelease: true,
  clearsAfterStop: true
})

SvgaPlayerV2({
  url: $r('app.media.example_animation'),
  controller: this.controller
})
  .width(300)
  .height(150)

Remote URL & Sandbox Playback

SvgaPlayerV2 accepts bundled $r resources, HTTPS URLs, and app sandbox file paths.

Remote URL & Sandbox Playback
ArkTS
SvgaPlayerV2({
  url: 'https://example.com/assets/gift.svga',
  controller: this.controller
})
  .width(300)
  .height(300)

Dynamic Replacement (setImage / setText)

Bind dynamic user images and text labels onto named slots through SvgaController.

setImage / setText
ArkTS
this.controller.setImage('https://example.com/avatar.png', 'avatar_slot')
this.controller.setText({
  text: 'VIP Lv.10',
  fontColor: '#FFFFFF',
  fontSize: 22
}, 'banner_text_slot')

Component Teardown

Use autoRelease: true and release the controller inside aboutToDisappear().

Lifecycle / Cache
ArkTS
aboutToDisappear(): void {
  this.controller.stop()
  this.controller.release()
}

Notes

  • Loads app resources, remote URLs, and sandbox file paths.
  • The controller supports playback control, image and text replacement, progress updates, and click events.
ECOSYSTEM

Additional runtimes & automation

Beyond native mobile and web browsers, SVGA is commonly integrated in mini programs and server pipelines.

TROUBLESHOOTING

Common production issues & fixes

CORS

Remote .svga URL fails to load on Web or Mobile Player

Missing Access-Control-Allow-Origin headers on CDN/OSS, or mixed HTTP requests from an HTTPS page.

Serve SVGA files over HTTPS with valid CORS headers and verify reachability in Mobile Player.

OOM

Low-end mobile devices lag or crash during gift playback

Decoded RGBA pixel memory ∑(width × height × 4) exceeds GPU/heap limits, or recycled views leak VideoEntity instances.

Inspect decoded RGBA memory in Online Player, downscale oversized sprites, and always call clear()/dispose() on teardown.

ProGuard

Android release APK crashes when parsing SVGA 2.0

R8/ProGuard stripped or renamed Wire and generated Protobuf classes.

Add -keep rules for com.squareup.wire.** and com.opensource.svgaplayer.proto.** in proguard-rules.pro.

Audio

Embedded sound is silent on Web players

Using Web Lite (no audio), missing global window.Howl in Classic player, missing ID3v2 header, or browser autoplay block.

Use svgaplayerweb 2.3.2 with howler.js triggered from a user interaction, or audition tracks natively in Online Player.

VERIFY & TEST

Test your integration with verified sample assets

Download open-source test files covering dynamic imageKey slots, matteKey masks, MP3 audio, and SVGA 1.x compatibility.