Getting Started

Requirements

In order to be able to use the Anyline SDK, only two requirements have to be met:

  • An Android device with Android SDK Level >= 21

  • An Android device with decent camera functionality (recommended: 720p and adequate auto focus)

If you are migrating from an Anyline version lower than 43, please also see Migrating to Anyline 43.0.0.

The Anyline SDK Developer Examples

If you rather like to jump into some code than to walk through a Quick Start Guide, a good starting point for development with the Anyline SDK, is to clone the Developer Examples for Android GitHub Repository.

It includes the following:

  • The source code of the Anyline OCR Examples App

  • The third party licenses

  • A Readme

Example Sheets for Mobile Scanning can be found here: Anyline Example Sheets

Quick Start Guide

This guide is going to lead you through the first steps when implementing the Anyline SDK on Android.

Generate an Anyline License

In order to run the Anyline SDK in your app, you require a license key.

In order to create a license key for your application, you have to identify the applicationId of your Android app.

  • Every license is bound to an applicationId. If you change your applicationId, you will require a new license. This also ensures that your license key cannot be used in any other application.

How to identify the Application ID

In your build.gradle file

On Android, the applicationId can be found in the build.gradle file of your app.

It is listed there under android > defaultConfig > applicationId

plugins {
    id 'com.android.application'
}
android {
    compileSdk 33

    defaultConfig {
        applicationId "io.anyline.examples.snapshot"
        minSdk 21
        targetSdk 33
        versionCode 200
        versionName "3.0"
    }
}

In your AndroidManifest.xml

If the applicationId is not used in the build.gradle file, you may use the package name of your application that is defined in the AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.anyline.examples">
</manifest>
With the applicationId you are now able to Generate a License.

Add AnylineSDK as dependency

The Anyline SDK for Android is provided as an .aar library.

From maven

To incorporate the Anyline SDK into your Android project effortlessly, follow these steps:

Step 1: Update build.gradle

Navigate to the root section of your app-level build.gradle file and add the Anyline Maven repository:

repositories {
    // Add the Anyline Maven repository
    maven { url 'https://mobile-sdk-android.anyline.io/release/'}
}
Step 2: Specify Anyline SDK Dependency

Inside the dependencies block of your app-level build.gradle file, include the Anyline SDK as a dependency. Replace LATEST_SDK_VERSION with the desired version, or use 51.4.1 for the latest version:

dependencies {
    // Include Anyline SDK as a dependency
    implementation 'io.anyline:anylinesdk:LATEST_SDK_VERSION'

    //... Add your other dependencies
}

This approach simplifies version management, allowing you to switch between versions effortlessly without manually downloading the updated SDK.

Step 3: Sync Project

After updating your build.gradle file, sync your project to apply the changes.

Now, you have successfully added the Anyline SDK to your Android project, enabling you to leverage its features seamlessly.

If you require to include the Anyline SDK as a local library in your project, please see Adding Anyline Mobile SDK for Android as a local dependency instead.

Integrate the License Key

Add the License Key as a Resource

You can add your License Key to a string resource file, or put it hard-coded into your Java file. However, we recommend to add a separate resource file (e.g. anyline_license_key.xml) to your res/values folder.

This should look like the following:

<resources>
	<string name="anyline_license_key" translatable="false">YOUR_LICENSE_KEY</string>
</resources>

Load the License Key in your Activity

In the Activity, where you initialise the Anyline SDK, you can access the License Key Resource the following way:

String licenseKey = getString(R.string.anyline_license_key);

Initialize the Android SDK with the License Key

Initialise the Anyline SDK before you do anything related to Anyline and handle the exception:

// This must be called before doing anything Anyline-related!
// Try/Catch this to check whether or not your license key is valid!
try {
    io.anyline2.AnylineSDK.init(getString(licenseKey), this);
} catch (LicenseException e) {
    // handle exception
}

Reduce App size

By default, the Anyline SDK ships trained models for all of our supported use cases. This will increase your app size significantly, but there is a simple way to remove the assets you do not need.

For a guide on how to do so, please follow Reduce SDK Size.

Load a Plugin and start scanning

Now you are all set to load one of the Anyline SDK Plugins and start scanning.

Do not forget: The Anyline SDK uses the camera for scanning - your application must request permission to use the camera!

The plugins on Android are described in detail at Plugins in the next section.