Migration from the Legacy Plugin to Infinity Plugin

This guide helps you migrate from the legacy Anyline plugin API to the Infinity Plugin API.

Key Differences

Aspect Legacy Plugin Infinity Plugin

Session model

One-shot (scan → result → done)

Persistent (init → scan → results 0..N → stop)

Configuration

Passed per scan call

ScanViewConfig JSON, switchable at runtime

Results

Single callback per scan

Event stream (0..N results per session)

Scan switching

Not supported (stop + restart)

Supported mid-session

Plugin class

Platform-specific class names

AnylineInfinityPlugin on all platforms

SDK initialization

Implicit or per-scan

Explicit requestSdkInitialization call

UCR support

Available (React Native only)

Built-in via requestUCRReport on all platforms

Cached events exporting

Available via exportCachedEvents

Built-in via requestExportCachedEvents

Migration Steps

Step 1: Update Dependencies

Replace the legacy plugin dependency with the latest version that includes the Infinity Plugin.

  • React Native

Install the Anyline plugin via npm or yarn:

npm install anyline-ocr-react-native-module
# or
yarn add anyline-ocr-react-native-module

On Android, add the Anyline Maven repository to your project. For Expo projects, add it to app.json:

app.json
{
  "expo": {
    "plugins": [
      ["expo-build-properties", {
        "android": {
          "extraMavenRepos": [
            "https://mobile-sdk-android.anyline.io/release/"
          ]
        }
      }]
    ]
  }
}

For bare React Native projects, add the repository to your project-level build.gradle or settings.gradle:

android/build.gradle
allprojects {
    repositories {
        maven { url 'https://mobile-sdk-android.anyline.io/release/' }
    }
}

Step 2: Update Imports

Replace legacy plugin imports with the Infinity Plugin:

  • React Native

import { AnylineInfinityPlugin } from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';

const infinityPlugin = new AnylineInfinityPlugin();

Step 3: Initialize the SDK Explicitly

The Infinity Plugin requires explicit SDK initialization before scanning. This replaces any implicit initialization in the legacy API.

  • React Native

const request = {
  licenseKey: 'YOUR_LICENSE_KEY', // Replace with your Anyline License Key
  // Optional: only needed if your app bundles custom ML model files provided by Anyline.
  // The value depends on where these files are placed in your project. See the Developer Examples.
  assetPathPrefix: 'anyline_assets',
};

const response = await infinityPlugin.requestSdkInitialization(request);

if (response.initialized) {
  console.log('SDK initialized:', response.succeedInfo);
} else {
  console.error('SDK init failed:', response.failInfo?.lastError);
}

Step 4: Update Scanning Code

Replace legacy scan calls with requestScanStart. The key difference is that results now arrive via an event stream rather than a single callback.

  • React Native

import {
  AnylineInfinityPlugin,
  ExportedScanResultImageFormat,
} from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';

// Subscribe to scan results before starting the scan
const subscription = infinityPlugin.onScanResults((result) => {
  const scanResult = result.exportedScanResults?.[0];
  console.log('Scan result:', scanResult?.pluginResult);
});

// Specify image format and delivery method for scan results
const scanResultConfig = {
  imageContainer: {
    encoded: {},
  },
  imageParameters: {
    format: ExportedScanResultImageFormat.Png,
    quality: 50,
  },
};

// scanViewConfigJson is a JSON string containing your ScanViewConfig
const request = {
  scanViewConfigContentString: scanViewConfigJson,
  scanResultConfig: scanResultConfig,
};

// requestScanStart resolves when the scan session ends
const response = await infinityPlugin.requestScanStart(request);
console.log('Scan session ended:', response.status);

// Clean up subscription when done
subscription.remove();

Step 5: Update Result Handling

The onScanResults event stream now delivers results as WrapperSessionScanResultsResponse objects. The result structure is similar to the legacy format but wrapped in the new response envelope.

See Scan Result Handling for details.

Step 6: Add Cleanup

  • React Native

The React Native plugin is a native module and does not require explicit disposal. Event subscriptions should be removed when no longer needed (see event stream documentation).

Breaking Changes

The Legacy Plugin and the Infinity Plugin are delivered in the same package, but they must not be used together in the same application.

Both plugins communicate with the native Anyline SDK through a shared internal session. Using both simultaneously causes:

  • Session state conflicts: the Legacy Plugin’s one-shot lifecycle and the Infinity Plugin’s persistent session compete for the same underlying connection, causing events (scan results, errors) to be routed unpredictably.

  • Initialization interference: each plugin triggers SDK initialization independently. Concurrent or interleaved initialization can lead to license validation errors or silent failures.

If you are migrating from the Legacy Plugin, complete the migration fully before removing legacy code. Do not call methods from both plugins within the same application lifecycle.

  • requestSdkInitialization must be called before any scan operations

  • The scan method no longer returns scan results directly. Subscribe to onScanResults instead.

  • The scan session lifecycle is explicit: you must call requestScanStop or wait for session end

  • Pass the ScanViewConfig as a JSON string, not as a native configuration object

Next Steps