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 libleadtools.so 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.
    LEADTOOLS license for Android
  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.

    LEADTOOLS license for Android compile
  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.

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

See Also

Setting a Runtime License

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

LEADTOOLS Imaging, Medical, and Document