Rubik is a comprehensive solution to componentization of the Android platform, providing routing and communication capabilities between gradle projects, as well as component definition, version control, maven release, switching between aar/jar and source code, and component freedom for gradle projects ability to combine.

English Readme

Rubik consists of two parts:

  • Rubik Router: Rubik’s function-level routing capability, which is different from general page routing. Rubik Router allows Uri and parameters to be navigated to the interior of the project, and any public JVM language (Java/Kotlin) function can be executed to facilitate More flexible communication between gradle projects that is not based on code calls.
  • Rubik tool chain: Provides the definition of component context, version control, maven release, switching between aar/jar and source code, etc., including 4 gradle plugins:
    • rubik:
      • Provide the ability to define components globally, and automatically enable plugins such as rubik-context and rubik-root according to the global definition
    • rubik-context:
      • Provide tasks, automatically generate intermediate codes such as mirror functions, and package the intermediate codes into context.jar, and publish them to maven according to the version number
      • Provide a task to compile the business code into aar (including code, resources, and built-in SDK) according to flavor and version number and publish it to maven
      • Through the globally defined components, other context.jar dependencies are automatically added to the subproject where the component is located
    • rubik-root:
      • Provide shell engineering with the ability to filter components, and filter business components to be packaged into apk according to flavor and version number
      • Provide source code engineering and aar switching capabilities of components
    • rubik-test:
      • Provide a unit test environment for the project

quick start

1. Project creation and component declaration:

(1) Create or use one or more existing android library modules as a “component project” (such as demo_component_detail, demo_component_home, etc. in the demo code) for developing real business logic.

(2) Configure initialization parameters such as the Rubik version number in the build.gradle or gradle.properties file of the outermost project (gradle root project), and enable the rubik plug-in in the outermost project:

ext {
    rubik_kapt_version = "com.rubik:kapt:1.9.1.1-K1_5"   
    rubik_router_version = "com.rubik:router:1.9.1.1-K1_5"   
    rubik_plugins_version = "com.rubik:plugins:1.9.1.1-AGBT4-K1_5"  
} 

apply plugin: 'rubik' // 启用rubik插件

(3) In the build.gradle file of the outermost project or the rubik-*.gradle file in the same directory, configure the component information:

rubik {
    component { // 第一个组件
        uri "app://com.myapp.home"  // 组件的Uri
        dependencies {    // 组件需要依赖的其他组件
            uri ("app://com.myapp.detail" ) { 
                version "0.1.1"  // 依赖其他组件的版本
            }
            uri( … ) 
        }
        source {    // 定义默认来源,如不需切换源码和aar,可以只声明project或maven
            project (":demo_component_home") 
        }
    }
    component { … }  //继续配置第二个组件
} 

2. Let the components communicate with each other:

(1). In the interface provider project, define the routing path through annotations as the communication interface that the component exposes to other components:

Declare function routing through the RFunction annotation:

@RFunction(path = "account/user") 
fun getUser(id : Int, name : String) : User? { 
    …
}

Declare page routing through RPage annotations:

@RPage(path = "page/main") 
class HomeActivity : AppCompatActivity() {
    … 
}

(2). Execute the “publishRubikXxxRContextLib” task corresponding to the interface provider project, and publish the component context to the cloud or local maven warehouse.

(3). Execute the “publishRubikXxxRComponent” task corresponding to the interface provider project, and publish the component aar to the cloud or the local maven warehouse.

(4). In the interface caller project, there are two ways to call the interface provided by the above interface provider:

Via the Kotlin DSL:

navigate {
    uri = "app://com.myapp.detail/account/user"  // 请求的uri
    query { // 请求的参数
        "id" with 400
        "name" with "CuiVincent" 
    }
    result<User?> { user -> 
    // 通过泛型指定接收数据类型,多次异步返回时,可以用多个result接收
        …
    }
} 

By auto-generated mirror function:

DetailContext.Account.user(400, "CuiVincent" ) { user ->
    … // 自动生成的镜像函数的参数类型、返回值类型都是明确的,比DSL方式更具有约束力
}

3. Filter the components to be packaged

(1). Create or use an existing android application project as a “shell project” (such as demo_root_app in demo code), which is used to assemble and compile components into Apk.

(2). In the build.gradle file of the “shell project” or the rubik-*.gradle file in the same level directory, specify which components the “shell project” will eventually import, and package them into the final Among the compiled products:

rubik {    
    packing {
        projectMode { // projectMode,通过源码工程的方式引入组件
            uri ("app://com.myapp.home")
            uri ("app://com.myapp.*") // 支持通过*匹配任意字符
        }
        mavenMode { // mavenMode,通过maven上的aar的方式引入组件
            uri ("app://com.myapp.detail") {
                version "0.2.0" 
            }
        }
    }
} 

test

  • Through the rubik-test plug-in, add context.jar dependencies of all pickable components to the androidTest variant of the current project, which is convenient for writing test cases.
@RunWith(AndroidJUnit4::class)
class RouterTestCase {
    @Before
    fun init() {
        Rubik.init()
    } // 初始化Rubik
    @Test
    fun usePerview() {
        PerviewContext.preViewVideo(path) { success ->
            log("preViewVideo success:${success}")
        } // 测试用例
    }
    … // 继续写测试用例
 }

#Rubik #Homepage #Documentation #Download #Android #Component #Development #Framework #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *