Setting your license with LEADTOOLS for Android Studio project

1. First, you will need to place the LEADTOOLS kernel as well as your license file in your Android Studio project. In your application's module, place leadtools.jar from /Bin/Java into the /libs folder. Create a /src/main/jniLibs folder, and then create a subfolder for the CPU architectures that you wish to support. In this example, we are supporting armeabi-v7a only. Place the appropriate version of from /Bin/Android/ into this folder. Finally, rename your license file such that it only contains lowercase letters. Then, create a /src/main/res/raw folder in your module and place the license file there.

2. Ensure that you are compiling leadtools.jar from the /libs folder. Open your module's build.gradle file and place one of the following lines in the 'dependencies' block. You can opt to compile all .jar files in the /libs folder, or compile individual files.

3. Finally, you will need to set your license at runtime. Here is an example on how to do so in onCreate() of your startup Activity. Be sure to replace "your_dev_key_goes_here" with your actual development key.


public class MainActivity extends AppCompatActivity { 
    private final String TAG = "MyTag"; 
    protected void onCreate(Bundle savedInstanceState) { 
        // Get shared libraries path for APK 
        String sharedLibsPath = ""; 
        if (Build.VERSION.SDK_INT < 9) 
            sharedLibsPath = String.format("%s/lib/", this.getApplicationInfo().dataDir); 
            sharedLibsPath = this.getApplicationInfo().nativeLibraryDir; 
        // Load LEADTOOLS native libraries 
        try { 
        catch (Exception ex) { 
            Log.d(TAG, "Failed to load LEADTOOLS native libraries"); 
        // Initialize and set license 
            RasterSupport.setLicense(getResources().openRawResource(R.raw.leadtools), "your_dev_key_goes_here"); 
        catch(Exception ex){ 
            Log.d(TAG, "Failed to set LEADTOOLS license"); 
        // Ensure that the LEADTOOLS kernel is not expired 
            Log.d(TAG, "LEADTOOLS kernel is expired"); 

See Also

Setting a Runtime License

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document