Rubik is a comprehensive solution for Android platform componentized development. It provides the ability of routing communication between Gradle projects, as well as the ability of component definition, version control, Maven publishing, AAR/JAR and source code switching, and free composition of components.
Rubik consists of two parts:
(1) Create or use one or more existing Android Library Modules as "component projects" (demo_component_detail, DEMO_component_home, etc. in Demo code) for developing real business logic.
(2) Set Rubik initialization parameters such as the Rubik version in the build.gradle or gradle.properties file of the gradle root project. and enable the Rubik plugin in the gradle root 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' // enable the Rubik plugin
(3) In the build.gradle file of the outermost project ,or rubik-*.gradle file in its sibling directory, configure the component information:
rubik {
component { // The first component
uri "app://com.myapp.home" // The Uri of component
dependencies { // The component needs to depend on other components
uri ("app://com.myapp.detail" ) {
version "0.1.1" // Versions that depend on other components
}
uri( … )
}
source { // Define the default source.
project (":demo_component_home")
}
}
component { … } // Proceed to configure the second component
}
(1). In the interface provider project, defined routing path by annotations, as a communication interface that a component exposes to other components:
Declare function route with the RFunction annotation:
@RFunction(path = "account/user")
fun getUser(id : Int, name : String) : User? {
…
}
Declare page route with the RPage annotation:
@RPage(path = "page/main")
class HomeActivity : AppCompatActivity() {
…
}
(2). Run "publishRubikXxxRContextLib" task in the interface provider project, release the component context to the cloud or local maven repository.
(3). Run "publishRubikXxxRComponent" task in the interface provider project, release the component aar to the cloud or local maven repository.
(4). In the interface caller project, there are two ways to call the interface provided by the above interface provider:
Via Kotlin DSL:
navigate {
uri = "app://com.myapp.detail/account/user" // The request uri
query { // Parameters of the request
"id" with 400
"name" with "CuiVincent"
}
result<User?> { user ->
// The received data type is specified by generics, and multiple asynchronous returns can be received as multiple results
…
}
}
Via automatically generated image functions:
DetailContext.Account.user(400, "CuiVincent" ) { user ->
… // The parameter type and return value type of the automatically generated image function are clear, which is more binding than the DSL
}
(1). Create or use an existing Android Application Project as a "shell project" (demo_root_app in demo code) to assemble and compile components to Apk.
(2). In the build.gradle file of the shell project or rubik-*.gradle file in its sibling directory, specify which components the shell project will eventually bring in and how they will be packaged into the final build product:
rubik {
packing {
projectMode { // projectMode,Introduce components through source code project
uri ("app://com.myapp.home")
uri ("app://com.myapp.*") // Support to match any character through *
}
mavenMode { // mavenMode,Introduce components through AAR on maven
uri ("app://com.myapp.detail") {
version "0.2.0"
}
}
}
}
@RunWith(AndroidJUnit4::class)
class RouterTestCase {
@Before
fun init() {
Rubik.init()
} // Initialize Rubik
@Test
fun usePerview() {
PerviewContext.preViewVideo(path) { success ->
log("preViewVideo success:${success}")
} // Test case
}
… // Continue to write test cases
}
Please write in Kotlin, and all change commit with reasonable motivation will be accepted.
Baidu 如流 discussion group :5425804
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。