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 |
|
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 |
|
SDK initialization |
Implicit or per-scan |
Explicit |
UCR support |
Available (React Native only) |
Built-in via |
Cached events exporting |
Available via |
Built-in via |
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:
{
"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:
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.
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:
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. |
-
requestSdkInitializationmust be called before any scan operations -
The scan method no longer returns scan results directly. Subscribe to
onScanResultsinstead. -
The scan session lifecycle is explicit: you must call
requestScanStopor wait for session end -
Pass the
ScanViewConfigas a JSON string, not as a native configuration object
Next Steps
-
Getting Started with Infinity Plugins — step-by-step setup with the Infinity Plugin
-
Infinity Plugin API Reference — complete method reference for the Infinity Plugin
-
Scan Result Handling — handling scan results and images