Getting Started

A note on the new SDK version

Anyline Android SDK version 43.0.0 is rewritten from the ground up, and features a wide range of performance and quality-of-life improvements.

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 Examples Bundle

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 download the Android SDK Bundle.

It includes the following:

  • The Anyline SDK in version 47.0.0 for offline integration

  • A build version of the Anyline OCR Examples App

  • The source code of the Anyline OCR Examples App

  • The Javadoc for the Anyline SDK

  • This documentation

  • The third party licenses

  • A Readme

  • The current Release Notes

Not included in the bundle are the Example Sheets with testing material. |br| They can be downloaded 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 32

    defaultConfig {
        applicationId "io.anyline.examples.snapshot"
        minSdk 21
        targetSdk 32
        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.

You can integrate the Anyline SDK into your app in two ways.

From maven

You can simply add the Anyline SDK as a dependency in your build.gradle. This way you can easily change versions, without having to download the new SDK version yourself. Replace LATEST_SDK_VERSION in the code block below with 47.0.0 (latest version).

//root section of the file
repositories {
    //add the anyline maven repo
    maven { url 'https://anylinesdk.blob.core.windows.net/maven/'}
}

dependencies {
    //load Anyline dependency
    implementation 'io.anyline:anylinesdk:LATEST_SDK_VERSION'

    //... your other dependencies
}

Locally

If you rather add the Anyline SDK locally as a lib, you can do so as well. To do so, you have to copy the .aar file to the libs directory of your Android project. This is usually located under app/libs.

You can download an offline version of the Anyline SDK from the Android SDK Bundle. Replace LATEST_SDK_VERSION in the code block below with 47.0.0 (latest version).

//root section of the file
repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    //load Anyline dependency
    implementation(name:'anylinesdk-LATEST_SDK_VERSION', ext:'aar')
    implementation("com.google.guava:guava:29.0-android")

    //... your other dependencies
}

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 seperate 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.