Add References and Set a License - Flutter Android

This tutorial shows how to get started with the LEADTOOLS SDK in a Flutter Android application.

Summary This tutorial covers how to set a license in a Flutter application using Android.
Completion Time 15 minutes
Project Download tutorial project (423 KB)
Platform Flutter (Java Android)
IDE Android Studio
Runtime License Download LEADTOOLS
Try it in another language

Required Knowledge

Before any functionality from the SDK can be leveraged, a valid runtime license will have to be set.

For instructions on how to obtain a runtime license, refer to Obtaining a License.

Create the Project

This tutorial builds upon the Writing custom platform-specific code directions.

You need to complete the steps up to step 3: Add an Android platform-specific implementation.

Configure the Project

Ensure the android folder is open in Android Studio. Select the File tab and open the android folder found in this project path: <APP_DIR>\batterylevel\android.

Open the <APP_DIR>\android\app folder and create a libs folder. Add the leadtools.jar into this folder. You can find leadtools.jar after installing the LEADTOOLS Android SDK in the following path: <INSTALL_DIR>\Bin\Java.

Add JAR file

Open the <APP_DIR>\android\app\src\main folder. Create a new folder in that directory and name it jniLibs. Add a subfolder for the CPU architecture that will be supported. This example will use x86_64 architecture. Copy the appropriate version of to this x86_64 subfolder. The .SO files can be found in the <INSTALL_DIR>\Bin\Android directory.

Add so file

Open the <APP_DIR>\android\app\src\main\res directory and create a folder named raw. Input the LEADTOOLS license LIC file inside the raw folder. Ensure the LIC file is named leadtools.lic, and that the naming convention does not include any capitalization in the name.

Input license file in RAW folder

Locate and open build.gradle. Add the following line in the dependencies block.

implementation fileTree(dir: 'libs', include: ['*.jar']) 
Edit gradle file

Add the Set License Code

Open the <APP_DIR>\android\app\src\main\java\ folder and locate the file. A license will need to be set in order to be able to access any LEADTOOLS SDK functionality. Add the code below to properly set your LEADTOOLS license. Be sure to replace "Input_Developer_Key_Here" with the development key that is being used.

import leadtools.LTLibrary; 
import leadtools.Platform; 
import leadtools.RasterSupport; 
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { 
        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL) 
                        (call, result) -> { 
                            // This method is invoked on the main thread. 
                            if (call.method.equals("getBatteryLevel")) { 
                                int batteryLevel = getBatteryLevel(); 
                                String sharedLibsPath = this.getApplicationInfo().nativeLibraryDir; 
                                catch(Exception ex) { 
                                    Log.d(TAG,"Failed to load LEADTOOLS Native libraries" ); 
                                    RasterSupport.setLicense(this, getResources().openRawResource(R.raw.leadtools), "Input_Developer_Key_Here"); 
                                catch(Exception ex) 
                                    Log.d(TAG, "Failed to set LEADTOOLS license"); 
                            if (batteryLevel != -1) { 
                                } else { 
                                    result.error("UNAVAILABLE", "Battery level not available.", null); 
                            } else { 

Run the Project

Run the project by pressing Shift + F10.

If the steps were followed correctly, the application runs and the license will be set when you press the Get Battery Level button.


This tutorial showed how to set a license in the android portion of a flutter application. This is the basis for all Flutter Android applications using the LEADTOOLS SDK. All the functionality in the SDK is unlocked via setting a license and setLicense must be called before calling any LEADTOOLS SDK methods.

After the SDK is purchased, the evaluation license can be replaced with a valid runtime license to disable the Nag Message.

See Also

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

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