preface

The company has internally developed routing framework, in order to adapt to Replugin plug-in framework, the current routing framework must not be used, due to the closed source situation, here is mainly about the idea of transformation

Original route design ideas and main problems

ARouter, for example, is designed only for componentialized architecture projects. Modules collect routing information through APT, and APP shell (APP shell) dynamically registers routing mapping table through reflection or through TranslateAPI + ASM technology.

The general design principle of our internal routing is similar. Obviously, there are several issues that arise when it comes to Replugin:

  1. RepluginWhen a component is invoked across plug-ins (such as an Activity jump)IntentYou need to set upComponentName(seeCall to the Replugin Wiki component), so we need to change the startup mode when we match the corresponding route for page hopping.

There are three ways a plug-in can invoke a plug-in’s component

Intent Intent = new Intent(); intent.setComponent(new ComponentName("demo2", "com.qihoo360.replugin.sample.demo2.databinding.DataBindingActivity")); context.startActivity(intent); Intent Intent = replugin. createIntent("demo2", "com.qihoo360.replugin.sample.demo2.databinding.DataBindingActivity"); context.startActivity(intent); StartActivity (v.getContext(), new Intent(), "demo2", "com.qihoo360.replugin.sample.demo2.databinding.DataBindingActivity");Copy the code

Replugin’s startActvityAPI must be used by the host component that calls the plug-in

RePlugin.startActivity(MainActivity.this, RePlugin.createIntent("demo1",
    "com.qihoo360.replugin.sample.demo1.MainActivity"));
Copy the code

  1. Due to theRepluginThe host and the plug-in use different classloaders, resulting in code-level isolation between the plug-in and the host, so the common way of dynamic registration through reflection or using ASM to obtain the routing mapping table cannot be solved.

A version of the transformation design ideas

Original reference information online, it is consider the plug-in to maintain their own routing mapping table, when the host dynamically loading plug-ins, take the initiative to start the plugin, routing framework provides a remote service by AIDL communication of each plug-in routing can be Shared, and jump on the component, the abstract with external business project initialization time to implement. The specific thinking process can be seen below



But then there are two problems:

  1. There is a performance cost to routing through AIDL
  2. Another very important problem is that at present, the routing protocol of internal routing cannot match the plug-in where the corresponding page is located. Then, when the host or plug-in needs to jump to the component under the plug-in according to the corresponding route, the plug-in to be started cannot be obtained from the routing information

Based on this, we went in another direction

Current adaptive plug-in routing design idea

Due to the problems mentioned above, we finally decided not to use the dynamic route loading scheme in the reference, but to use the unified management of the routing table by the host. So this can also rule out that when the route cannot be found, it is necessary to determine whether the target plug-in is not started or not down (for the case of built-in plug-in). The main ideas are as follows:

  1. The plugin collects routing information through APT at compile time and generates JSON files to be stored in assets
  2. For built-in plug-ins, after inserting them into assets/plugins folder of the host, refer to the practice of Gradle Plugin, the host of Replugin, parse the plug-in to obtain the routing table in the resources of the plug-in, copy it into assets of the host, and maintain it by the host. For external plug-in, it is necessary to upload the routing table with the plug-in upload, and the host can request the server to obtain the route of external plug-in during initialization (the route acquisition scheme of external plug-in is only envisaged at present, and has not been implemented due to the current demand environment).
  3. At initialization, the host retrieves the route JSON, which is parsed and stored in memory.

Then according to the above process, routing needs to be done mainly in the original annotation processing logic modification and plugin modification, relatively speaking, the change is not big.

reference

  1. Router: how to implement Router adaptation in any plug-in environment