Skip to content

How to build a plugin

The following guide drives you through the steps of creating a plugin from scratch.

  1. Create a plugin module in Android Studio

    Android Studio Module

  2. Import platformhub in Gradle

    groovy
    implementation "com.skyrin.mobilebanking:platformhub:<latest-version>"
  3. Create a plugin policy

    Learn more in the article > Plugin policy.

    json
    {
      "name": "PluginName",
      "publish": {
        "eventStreams": []
      },
      "subscribeOnStartup": {
        "eventStreams": []
      },
      "subscribeOnDemand": {
        "eventStreams": []
      },
      "send": {
        "commands": [],
        "navigationQueries": [],
        "queries": []
      },
      "receive": {
        "commands": [],
        "navigationQueries": [],
        "queries": []
      },
      "dependencies": []
    }
  4. Implement the Plugin interface

    kotlin
    @Singleton
    class MyPlugin @Inject constructor(private val assetsLoader: AssetsLoader) : Plugin {
    
       private lateinit var context: Context
       private lateinit var configurationFiles: Map<String, InputStream>
    
       override fun init(
          context: Context,
          configurationFiles: Map<String, InputStream>
       ) {
          this.context = context
          this.configurationFiles = configurationFiles
       }
    
       override val policyFilename = POLICY_FILE
    
       override fun publish(eventStream: BaseMessage.EventStream): SharedFlow<EventStreamOutput> = MutableSharedFlow()
    
       override fun subscribeOnStartup(subscription: SharedFlow<EventStreamOutput>,eventStream: BaseMessage.EventStream) {}
    
       override fun onReceive(message: BaseMessage.Query): JSONObject> = JSONObject("{}")
    
       override fun onReceive(message: BaseMessage.Command) {}
    
       override fun postMicroKernelInit() {}
    
       companion object {
          const val TAG = "my-plugin"
          const val POLICY_FILE = "my-plugin-policy.json"
       }
    }
  5. To use platformhub-navigation Plugin needs to implement at least one of the router interfaces.

Note:

  • When MicroKernel hasn't been initialized yet, and your plugin is attempting to send a message, you can get MicroKernelUninitializedException.
  • To resolve this, ensure that your plugin only sends a messages after Microkernel gets initialized. You can use postMicrokernelInit() function (this function is a part of PlatformHub), to check plugin is initialized or not.