Skip to content

RouteTable

Season edited this page Dec 8, 2023 · 1 revision

Introduction

During the compilation process of Butterfly, a corresponding routing table is generated for each module in the project, and each routing table is a subclass of Module.

The naming convention for routing table classes is: class Butterfly[ModuleNname]Module

For example, there are the following modules:

The compiled routing table classes are: ButterflyFeature1Module,ButterflyFeature2Module,ButterflyNormalModule

The generated routing table class is located in the build folder in the module:

Manual Registration

You can register the routing table manually through ButterflyCore.

ButterflyCore.addModule(ButterflyFeature1Module())
ButterflyCore.addModule(ButterflyFeature2Module())
ButterflyCore.addModule(ButterflyNormalModule())

Automatic Registration

The routing table can be automatically registered through the plug-in provided by Butterfly. During the compilation process, the plug-in scans all generated Module classes and realizes automatic registration through ASM bytecode processing technology.

1. Installing plugins

//using plugins DSL:
plugins {
    id "io.github.ssseasonnn.butterfly" version "1.0.1"
}

//or using legacy plugin application:
buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "io.github.ssseasonnn:plugin:1.0.1"
    }
}

//apply plugin
apply plugin: "io.github.ssseasonnn.butterfly"

2. Implement the Application class

Plugin automatic registration is to insert the code for registering routing tables into the onCreate method of the Application, so a custom Application class is required in the project.

class TestApplication : Application() {
    override fun onCreate() {
        super.onCreate()
    }
}