Using plugins in Kanzi Android framework (droidfw)

Using Kanzi Engine Java plugins

To learn about creating Kanzi Engine Java plugins, see Creating Kanzi Engine Java plugins.

To use a plugin in your Android application, either:

  • Load the plugin during the initialization of an Activity.

    @Override
    protected void onCreate(Bundle icicle)
    {
        ...
    
        KanziRuntime.Reference runtimeRef = KanziRuntime.acquire(this);
        runtimeRef.get().getDomain().registerPlugin(new MyPlugin());
    
        ...
    }
    
    Copy to clipboard
    override fun onCreate(icicle: Bundle) {
        ...
    
        val runtimeRef = KanziRuntime.acquire(this)
        runtimeRef.get().domain.registerPlugin(new MyPlugin());
    
        ...
    }
    
    Copy to clipboard
  • Load the plugin when your application attaches a Kanzi view that uses the plugin.

    view.addListener(new KanziViewListener() {
       ...
    
       @Override
       public void onAttachedToWindow(View view, Domain domain)
       {
             domain.registerPlugin(new MyPlugin());
    
             ...
       }
       ...
    }
    
    Copy to clipboard
    view.addListener(object : KanziViewListener {
       ...
    
       override fun onAttachedToWindow(view: View, domain: Domain) {
             domain.registerPlugin(MyPlugin())
    
             ...
       }
       ...
    }
    
    Copy to clipboard

Using Kanzi Studio generated plugins

Kanzi Studio automatically generates plugins for some features, such as Code Behind, and adds the registration for these plugins to the KanziGenerated.java file.

To use these plugins, during the initialization of your activities or the attachment of your Kanzi views, call KanziGenerated.registerPlugins(domain). This is similar to the registration of individual plugins in Using Kanzi Engine Java plugins.

Using Kanzi Engine C++ plugins

To use a Kanzi Engine C++ plugin:

  1. Export the Kanzi Engine plugin:

    1. In Kanzi Studio open the project that contains the plugin code.

      For example, open <KanziWorkspace>/Tutorials/Data sources/Completed/Tool_project/XML data source.kzproj.

    2. In the Library > Build Configurations select the plugin and in the Properties set:

      • CPU Architecture to match the architecture of your device

      • Build Profile to the configuration that you want to use

      ../../../_images/library-build-configurations.png ../../../_images/properties-build-configuration.png
    3. Select File > Export > Build Android Package.

      Kanzi Studio builds the Kanzi Engine plugin in <ProjectName>/Application/output/cmake/<PluginProjectName>/cmake/release/arm64-v8a/lib<PluginProjectName>.so.

      For example, if you use the XML data source plugin, Kanzi Studio builds the plugin in <KanziWorkspace>/Tutorials/Data sources/Completed/Application/output/cmake/XML_data_source/cmake/release/arm64-v8a/libXML_data_source.so.

      ../../../_images/export-build-android-package.png
  2. Add the built Kanzi Engine plugin to an application:

    1. In Kanzi Studio select File > Close All projects and open or create a Kanzi Studio project using the Android application template.

      Android application template creates a Kanzi Studio project with a Kanzi Android framework-based application.

      ../../../_images/close-all-projects.png ../../../_images/new-project-android-application1.png
    2. In the Library right-click Kanzi Engine Plugin, select Import Kanzi Engine Plugin, and select the dll of the built plugin.

      For example, select the <KanziWorkspace>/Tutorials/Data sources/Completed/Application/lib/Win64/GL_vs2019_Release_DLL/XML_data_source.dll plugin.

      This way you add Kanzi Engine plugin to a Kanzi Studio project.

      ../../../_images/import-kanzi-engine-plugin1.png
    3. In File Explorer in the project to which you want to add this Kanzi Engine plugin, create this directory structure <ProjectName>/Application/lib/Android/release/arm64-v8a.

    4. Copy the Kanzi Engine so plugin file from <ProjectName>/Application/output/cmake/<PluginProjectName>/cmake/release/arm64-v8a/lib<PluginProjectName>.so to the <ProjectName>/Application/lib/Android/release/arm64-v8a directory.

      For example, copy the <KanziWorkspace>/Tutorials/Data sources/Completed/Application/output/cmake/XML_data_source/cmake/release/arm64-v8a/libXML_data_source.so file.

    5. Edit the <ProjectName>/Application/CMakeLists.txt file to add the Kanzi Engine plugin as an imported library dependency:

      add_library(<PluginProjectName> SHARED IMPORTED)
      set_target_properties(<PluginProjectName> PROPERTIES IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/lib/Android/release/${ANDROID_ABI}/lib<PluginProjectName>.so")
      target_link_libraries(<ProjectName> <PluginProjectName>)
      
      Copy to clipboard

      For example, to add the XML data source plugin, use:

      add_library(XML_data_source SHARED IMPORTED)
      set_target_properties(XML_data_source PROPERTIES IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/lib/Android/release/${ANDROID_ABI}/libXML_data_source.so")
      target_link_libraries(<ProjectName> XML_data_source)
      
      Copy to clipboard

      This way you add the built native Kanzi Engine plugin to your Android application.

      With this CMake configuration, you link a dynamically linked Kanzi Engine plugin to your Android application during build time. This way, when you add to your application a kzb file with a plugin dependency, Kanzi is able to load that plugin.

  3. In Kanzi Studio select File > Export > Build Android Package.

    Kanzi Studio builds and deploys your application to an Android device. When application starts running on your Android device, in the logcat you can see when the application loads the plugin.

    For example, if you use the XML data source plugin, the logcat shows:

    I/Kanzi: [info:generic] Loading plugin 'libXML_data_source.so'
    
    Copy to clipboard
    ../../../_images/export-build-android-package.png
  4. Use the plugin in the Kanzi Android framework (droidfw) application.

    For example, to learn how to use a Kanzi Engine data source plugin, see Using a data source.