Get Started with Maven Artifacts - Java Android

This tutorial shows how to add Maven artifacts in a Java Android application using the LEADTOOLS SDK.

Overview  
Summary This tutorial shows how to use the Maven LEADTOOLS SDK in an Java Android application.
Completion Time 10 minutes
Platform Java (Android)
IDE Android Studio
Development License Download LEADTOOLS

Required Knowledge

Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License and Recognize Text from Images with OCR - Android Java tutorials before working on the Get Started with Maven Artifacts - Java Android tutorial.

For code examples, refer to Get Started with Maven - Java Android and Recognize Text from Images with OCR - Android Java.

You can get a jump start on your development by downloading LEADTOOLS Evaluation - Android Native Binaries and Projects.

Create the Project

Start with a copy of the project created in the Add References and Set a License tutorial. If you do not have that project, follow the steps in that tutorial to create it.

Setting your License and Getting Started

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:

Note

Adding LEADTOOLS local references and setting a license are covered in more detail in the Add References and Set a License tutorial.

 

To begin, 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.

Add the Maven repository and artifacts as described in the Get Started with Maven - Java Android topic.

Artifact Details

Artifact Artifact Dependencies JARs Native Libraries
annotations org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:formats.raster.common:22.0.1 core-for-system-modules.jar
com.android.tools.lint:lint-gradle:30.0.3 leadtools.annotations.engine.jar
leadtools.annotations.designers.jar
leadtools.annotations.rendering.android.jar
leadtools.annotations.automation.jar
leadtools.annotations.batesstamp.jar
barcode org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.barcode.datamatrixread.so
leadtools:kernel:22.0.1 core-for-system-modules.jar libleadtools.barcode.datamatrixwrite.so
leadtools:formats.raster.common:22.0.1 leadtools.barcode.jar libleadtools.barcode.lead2dread.so
leadtools:image.processing:22.0.1 libleadtools.barcode.lead2dwrite.so
leadtools:forms:22.0.1 libleadtools.barcode.oned.so
com.android.tools.lint:lint-gradle:30.0.3 libleadtools.barcode.pdfread.so
libleadtools.barcode.pdfwrite.so
libleadtools.barcode.qrread.so
libleadtools.barcode.qrwrite.so
libleadtools.barcode.so
dicom org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.dicom.so
leadtools:kernel:22.0.1 core-for-system-modules.jar
leadtools:image.processing:22.0.1 leadtools.dicom.jar
leadtools:formats.raster.common:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
document.analytics org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.regex.so
leadtools:kernel:22.0.1 core-for-system-modules.jar
com.android.tools.lint:lint-gradle:30.0.3 leadtools.regex.jar
leadtools.document.analytics.jar
leadtools.document.unstructured.jar
document.sdk org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:kernel:22.0.1 core-for-system-modules.jar
leadtools:formats.raster.common:22.0.1 leadtools.caching.jar
leadtools:formats.document:22.0.1 leadtools.document.jar
leadtools:formats.vector:22.0.1 leadtools.document.pdf.jar
leadtools:forms:22.0.1 leadtools.document.raster.jar
leadtools:pdf:22.0.1 leadtools.document.converter.jar
leadtools:annotations:22.0.1
leadtools:pdf.annotations.converter:22.0.1
leadtools:barcode:22.0.1
leadtools:ocr:22.0.1
leadtools:document.writer:22.0.1
leadtools:image.processing:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
document.writer org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.document.writer.so
leadtools:kernel:22.0.1 core-for-system-modules.jar
leadtools:formats.raster.common:22.0.1 leadtools.document.writer.jar
leadtools:image.processing:22.0.1
leadtools:annotations:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
formats.document org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.codecs.doc.so
leadtools:kernel:22.0.1 core-for-system-modules.jar libleadtools.codecs.dox.so
leadtools:formats.raster.common:22.0.1 libleadtools.codecs.ppt.so
leadtools:image.processing:22.0.1 libleadtools.codecs.ppx.so
com.android.tools.lint:lint-gradle:30.0.3 libleadtools.codecs.xls.so
libleadtools.codecs.xlx.so
libleadtools.codecs.txt.so
libleadtools.codecs.rtf.so
formats.raster.additional org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.codecs.img.so
leadtools:kernel:22.0.1 core-for-system-modules.jar libleadtools.codecs.pcx.so
leadtools:formats.raster.common:22.0.1 libleadtools.codecs.abi.so
com.android.tools.lint:lint-gradle:30.0.3 libleadtools.codecs.cal.so
libleadtools.codecs.ica.so
libleadtools.codecs.lmb.so
libleadtools.codecs.psd.so
libleadtools.codecs.eps.so
libleadtools.codecs.jls.so
libleadtools.codecs.jpm.so
libleadtools.codecs.jxr.so
libleadtools.codecs.afp.so
libleadtools.codecs.ptk.so
libleadtools.codecs.heif.so
formats.raster.common org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.codecs.bmp.so
leadtools:kernel:22.0.1 core-for-system-modules.jar libleadtools.codecs.fax.so
com.android.tools.lint:lint-gradle:30.0.3 libleadtools.codecs.png.so
libleadtools.codecs.raw.so
libleadtools.codecs.tif.so
libleadtools.codecs.tfx.so
libleadtools.codecs.gif.so
libleadtools.codecs.cmp.so
libleadtools.codecs.jbg.so
libleadtools.codecs.jb2.so
libleadtools.codecs.j2k.so
libleadtools.codecs.cmw.so
libleadtools.colorconversion.so
formats.vector org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.codecs.cgm.so
leadtools:kernel:22.0.1 core-for-system-modules.jar libleadtools.codecs.cmx.so
com.android.tools.lint:lint-gradle:30.0.3 libleadtools.codecs.dwg.so
libleadtools.codecs.dxf.so
libleadtools.codecs.e00.so
libleadtools.codecs.gbr.so
libleadtools.codecs.mif.so
libleadtools.codecs.nap.so
libleadtools.codecs.pcl.so
libleadtools.codecs.pct.so
libleadtools.codecs.shp.so
libleadtools.codecs.3js.so
libleadtools.vector.so
forms org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:kernel:22.0.1 core-for-system-modules.jar
com.android.tools.lint:lint-gradle:30.0.3 leadtools.forms.common.jar
leadtools.forms.commands.jar
leadtools.forms.Processing.Omr.jar
leadtools.forms.recognition.barcode.jar
leadtools.forms.recognition.jar
leadtools.forms.recognition.ocr.jar
leadtools.forms.recognition.search.jar
image.processing org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.imageprocessing.color.so
leadtools:kernel:22.0.1 core-for-system-modules.jar libleadtools.imageprocessing.core.so
com.android.tools.lint:lint-gradle:30.0.3 leadtools.imageprocessing.color.jar libleadtools.imageprocessing.effects.so
leadtools.imageprocessing.core.jar libleadtools.imageprocessing.utilities.so
leadtools.imageprocessing.effects.jar
kernel org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.so
com.android.tools.lint:lint-gradle:30.0.3 core-for-system-modules.jar libleadtools.codecs.so
leadtools.jar libleadtools.drawing.so
leadtools.codecs.jar libleadtools.svg.so
leadtools.converters.android.jar libleadtools.document.core.so
leadtools.drawing.jar
leadtools.svg.jar
ocr org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:image.processing:22.0.1 core-for-system-modules.jar
leadtools:ocr.kernel:22.0.1
leadtools:ocr.languages.main:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
ocr.kernel org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.ocr.so
leadtools:kernel:22.0.1 core-for-system-modules.jar libleadtools.icr.so
leadtools:forms:22.0.1 leadtools.ocr.jar libleadtools.ml.so
leadtools:document.writer:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
ocr.languages.additional org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:kernel:22.0.1 core-for-system-modules.jar
leadtools:ocr:22.0.1
com.android.tools.lint:lint-gradle:30.0.3

OCR Language Files
LEAD.af.bin
LEAD.af.dic
LEAD.az.bin
LEAD.be.bin
LEAD.be.dic
LEAD.bg.bin
LEAD.bg.dic
LEAD.ca.bin
LEAD.ca.dic
LEAD.cs.bin
LEAD.cs.dic
LEAD.da.bin
LEAD.da.dic
LEAD.el.bin
LEAD.el.dic
LEAD.et.bin
LEAD.et.dic
LEAD.eu.bin
LEAD.fi.bin
LEAD.gl.bin
LEAD.hr.bin
LEAD.hr.dic
LEAD.hu.bin
LEAD.hu.dic
LEAD.id.bin
LEAD.id.dic
LEAD.is.bin
LEAD.is.dic
LEAD.lt.bin
LEAD.lt.dic
LEAD.lv.bin
LEAD.lv.dic
LEAD.mk.bin
LEAD.mk.dic
LEAD.ms.bin
LEAD.ms.dic
LEAD.mt.bin
LEAD.mt.dic
LEAD.nl.bin
LEAD.nl.dic
LEAD.no.bin
LEAD.no.dic
LEAD.pl.bin
LEAD.pl.dic
LEAD.pt.bin
LEAD.pt.dic
LEAD.ro.bin
LEAD.ro.dic
LEAD.ru.bin
LEAD.ru.dic
LEAD.sk.bin
LEAD.sk.dic
LEAD.sl.bin
LEAD.sl.dic
LEAD.sq.bin
LEAD.sq.dic
LEAD.sr.bin
LEAD.sr.dic
LEAD.sv.bin
LEAD.sv.dic
LEAD.sw.bin
LEAD.sw.dic
LEAD.te.bin
LEAD.th.bin
LEAD.th.dic
LEAD.tr.bin
LEAD.uk.bin
LEAD.uk.dic
LEAD.vi.bin
LEAD.vi.dic
LEAD.zh-Hans.bin
LEAD.zh-Hant.bin
LEAD.ja.bin
LEAD.ja.bin2
LEAD.ko.bin
LEAD.ko.dic
LEAD.en.bin
LEAD.en.bin2
LEAD.en.dic
LEAD.de.bin
LEAD.de.dic
LEAD.fr.bin
LEAD.fr.dic
LEAD.it.bin
LEAD.it.dic
LEAD.es.bin
LEAD.es.dic
LEAD.Field.bin
LEAD.Micr.bin
LEAD.Mrz.bin
LEAD.Cmc7.bin
LEAD.icr.en.p1.bin
LEAD.icr.en.p2.bin
LEAD.icr.en.p3.bin
LEAD.icr.en.p4.bin
LEAD.icr.en.p5.bin
LEAD.icr.en.p6.bin
LEAD.icr.en.p7.bin
LEAD.icr.en.p8.bin
ocr.languages.asian org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:kernel:22.0.1 core-for-system-modules.jar
leadtools:ocr:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
ocr.languages.main org.jacoco:org.jacoco.ant:0.8.3 android.jar
com.android.tools.lint:lint-gradle:30.0.3 core-for-system-modules.jar
pdf org.jacoco:org.jacoco.ant:0.8.3 android.jar libleadtools.pdf.so
leadtools:kernel:22.0.1 core-for-system-modules.jar
leadtools:formats.raster.common:22.0.1 leadtools.pdf.jar
leadtools:image.processing:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
pdf.annotations.android org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:pdf.annotations.converter:22.0.1 core-for-system-modules.jar
leadtools:viewer.controls.android:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
pdf.annotations.converter org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:kernel:22.0.1 core-for-system-modules.jar
leadtools:annotations:22.0.1 leadtools.pdf.annotations.jar
leadtools:pdf:22.0.1
com.android.tools.lint:lint-gradle:30.0.3
substitutionfonts org.jacoco:org.jacoco.ant:0.8.3 android.jar
com.android.tools.lint:lint-gradle:30.0.3 core-for-system-modules.jar

Substitution Fonts
lt-couriercode-bold.ttf
lt-couriercode-bolditalic.ttf
lt-couriercode-italic.ttf
lt-couriercode-roman.ttf
lt-crimsontext-bold.ttf
lt-crimsontext-bolditalic.ttf
lt-crimsontext-italic.ttf
lt-crimsontext-regular.ttf
lt-dejavuserif-bold.ttf
lt-dejavuserif-bolditalic.ttf
lt-dejavuserif-italic.ttf
lt-dejavuserif.ttf
lt-droidsansfallbackfull.ttc
lt-droidsansthai.ttf
lt-ebgaramondsc08-regular.ttf
lt-liberationsans-bold.ttf
lt-liberationsans-bolditalic.ttf
lt-liberationsans-italic.ttf
lt-liberationsans-regular.ttf
lt-liberationserif-bold.ttf
lt-liberationserif-bolditalic.ttf
lt-liberationserif-italic.ttf
lt-liberationserif-regular.ttf
lt-pt _sans-narrow-bold.ttf
lt-pt _sans-narrow-regular.ttf
lt-robotomono-bold.ttf
lt-robotomono-bolditalic.ttf
lt-robotomono-italic.ttf
lt-robotomono-regular.ttf
lt-texgyrebonum-bold.otf
lt-texgyrebonum-bolditalic.otf
lt-texgyrebonum-italic.otf
lt-texgyrebonum-regular.otf
lt-vera.ttf
lt-verabd.ttf
lt-verabi.ttf
lt-verait.ttf
viewer.controls.android org.jacoco:org.jacoco.ant:0.8.3 android.jar
leadtools:kernel:22.0.1 core-for-system-modules.jar
com.android.tools.lint:lint-gradle:30.0.3 leadtools.controls.android.jar

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:

Java
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(); 
    } 
} 

To illustrate the addition of substitution fonts and OCR language files, there is a tutorial to Recognize text from Images with OCR you can refer to.

Recommendations

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

Our Android demos are currently tested and shipped using Gradle build tools 7.0.3.

Root build.gradle file:

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

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

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

Run the Project

Press Shift + F10 to run the application.

If the steps were followed correctly, the application runs with the LEADTOOLS license set.

Wrap-up

This tutorial showed how to use the LEADTOOLS Maven artifacts in a Java Android project.

See Also

Help Version 22.0.2022.8.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2022 LEAD Technologies, Inc. All Rights Reserved.


Products | Support | Contact Us | Intellectual Property Notices
© 1991-2022 LEAD Technologies, Inc. All Rights Reserved.