Below are instructions to utilize the LEADTOOLS Maven Repository. In addition to the using this repo, you can get a jump start on your development by downloading LEADTOOLS Evaluation - Android Native Binaries and Projects.

Usage in Android Studio

Add the following 'repositories' block to your module's build.gradle file:

repositories { 
    google()
    maven { url "https://www.leadtools.com/rd/v200/android-repo" } 
}

Then, add LEADTOOLS artifacts to your module's 'dependencies' block as needed:

Artifact Details

Artifact Artifact Dependencies JARs Native Libraries OCR Language Files Substitution Fonts

 Setting Your License and Getting Started

To begin, you will need to add the 'core' artifact to your project, which includes the LEADTOOLS kernel. You will also need a license file and a development key, which can be obtained via email by filling out the form here. Place your license file in the <module>/src/main/res/raw folder of your application. This folder is not created by default, so you will have to create it yourself. Raw file resources must have all lowercase file names. For the sake of this example, we will name our license file 'leadtools.lic'.

import leadtools.demos.*;
import leadtools.*;
   
public class MainActivity extends AppCompatActivity {
      
   private final String TAG = "MainActivity";
            
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
         
      // Load native libraries
      try {
         Platform.setLibPath(Utils.getSharedLibsPath(this));
         
         //LEADTOOLS kernel
         Platform.loadLibrary(LTLibrary.LEADTOOLS);
         
         // Load further native libraries as needed...
         //Platform.loadLibrary(LTLibrary.CODECS);
         //Platform.loadLibrary(LTLibrary.BARCODE);
         //Platform.loadLibrary(LTLibrary.DICOM);
         //Platform.loadLibrary(LTLibrary.PDF);
         //Platform.loadLibrary(LTLibrary.DOCUMENT_CONVERTER);
         //Platform.loadLibrary(LTLibrary.DOCUMENT);
         //Platform.loadLibrary(LTLibrary.DOCUMENT_WRITER);
         //Platform.loadLibrary(LTLibrary.CREDIT_CARDS);
         //Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_CORE);
         //Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_COLOR);
         //Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_EFFECTS);
         //Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_KERNEL);
         //Platform.loadLibrary(LTLibrary.SVG);
         //Platform.loadLibrary(LTLibrary.OCR);
      }
      catch (Exception ex) {
         Log.d(TAG, "Failed to load LEADTOOLS native libraries");
         finish();
      }
            
      // TODO: 
      // Place LEADTOOLS license file in /src/main/res/raw/
      // Ensure that the file name is all lowercase, eg. license.lic
      // Uncomment the line below for your license resource
      // and replace "dev_key" with your LEADTOOLS developer key
      int licenseResourceId = 0; // R.raw.license;
      Support.setLicense(this, licenseResourceId, "dev_key");
            
      // Ensure that the LEADTOOLS kernel is not expired
      if(RasterSupport.getKernelExpired()){
         Log.d(TAG, "LEADTOOLS kernel is expired");
         finish();
      }
         
      //...
   }
}

Utilizing OCR Language Files and Substitution Fonts

The LEADTOOLS OCR Language Files in the artifacts above will be placed in the <module>/src/main/assets/ocr_runtime/ folder of your application. Substitution Fonts will be placed in the <module>/src/main/assets/substitution_fonts/ folder. To successfully startup the LEADTOOLS OCR Engine or write documents with accurate font representations, you will need to copy OCR Language Files and Substitution Fonts, respectively, to the device's SD card. To do this, you will need the following permissions in your application's manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="true" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

If you are supporting devices running Android 6.0 (API level 23) or higher, you will also want to request WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE at runtime.

With the appropriate permissions, you can begin copying files:


import leadtools.demos.*;
import leadtools.*;
import leadtools.ocr.*;
public class MainActivity extends AppCompatActivity {
   private final String TAG = "MainActivity";
   private OcrEngine mOcrEngine;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      
      //Request permissions, load libraries, set license, etc.
      //...
      
      //Copy resource files
      String sdCardRoot = Environment.getExternalStorageDirectory().getPath();
      if (!sdCardRoot.endsWith("/"))
         sdCardRoot += "/";
      
      String resourceDir = sdCardRoot + "MyApp/";         
      String ocrLanguageFileDir = resourceDir + "OCRRuntime";
      String substitutionFontsDir = resourceDir + "SubstitutionFonts";
      
      if(!Utils.copyOcrRuntimeFiles(this, ocrLanguageFileDir)) {
         Log.d(TAG, "Failed to copy OCR Language Files");
         finish();
      }
      
      if(!Utils.copyAssetsFiles(this, "substitution_fonts", substitutionFontsDir)) {
         Log.d(TAG, "Failed to copy Substitution Fonts");
         finish();
      }
      
      //Set Substitution Fonts path and startup the OCR Engine
      try {
         RasterDefaults.setResourceDirectory(LEADResourceDirectory.FONTS, substitutionFontsDir);
         mOcrEngine = OcrEngineManager.createEngine(OcrEngineType.ADVANTAGE);
         mOcrEngine.startup(null, null, null, ocrLanguageFileDir);
      } 
      catch(Exception ex) {
         Log.d(TAG, "Failed to create/start OCR Engine");
         finish();
      }
      //...
   }
   
   @Override
   protected void onDestroy(){
      super.onDestroy();
	  if(mOcrEngine != null)
		mOcrEngine.dispose();
   } 
   
}

Recommendations

The artifacts above contain native libraries for the following Application Binary Interfaces (ABIs):

  • x86_64
  • x86
  • arm64-v8a
  • armeabi-v7a
  • armeabi

NOTE: mips and mips64 builds of LEADTOOLS libraries can be made available by specific request.

Packaging all of these libraries in a single APK can be very costly in terms of file size. Instead of building a single APK, we recommend configuring ABI APK splits in your application like so:

android{
   splits {
        abi {
            enable true
            reset()
            include 'x86_64', 'x86', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
            universalApk false
        }
    }
}

For more information, see this page.

Our Android demos are currently tested and shipped using Gradle build tools 3.3.0:

Root build.gradle file:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}

In <app_root>/gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip