1 Star 1 Fork 0

百度开源 / Rubik

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README_en.md 6.94 KB
一键复制 编辑 原始数据 按行查看 历史
CuiVincent 提交于 2022-08-04 17:59 . Update README_en.md

license platform language last release

Rubik

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:

  • Rubik Router :The function level routing capability of Rubik. Unlike normal page router, Rubik Router allows the Uri and parameters to be navigated to any execution of a public JVM language (Java/Kotlin) function . It allows for more flexible communication between Gradle Projects without code calls.
  • Rubik Tools link :Provides component context definition, versioning, Maven publishing, AAR/JAR and source switching capabilities, including 4 Gradle Plugins:
    • rubik:
      • Provides the ability to define components globally, and automatically enables plugins such as rubik-context and rubik-root based on the global definition
    • rubik-context:
      • Provide Task, automatically generate the intermediate code such as mirror function, and package the intermediate code into context.jar, release to Maven according to the version.
      • Provides tasks to compile business codes into AAR (including code, resources, and built-in SDK) based on flavor and version. publish them to Maven.
      • Automatically adds dependencies on other context.jars to subprojects where components reside
    • rubik-root:
      • Provides the ability to picking components, picking components to be packaged into APK based on flavor and version.
      • Provide component source code and AAR switching ability.
    • rubik-test:
      • Provide unit testing environment for projects

Quick start

1. Project creation and component declaration:

  (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
} 

2. Let components communicating to each other.:

  (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
}

3. Picking components to package

  (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" 
            }
        }
    }
} 

Test

  • Through the rubik-test plugin, add all the context.jar dependencies of picked components to androidTest Variant of the current project, which is easy to write test cases.
@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
}

How to contribute

Please write in Kotlin, and all change commit with reasonable motivation will be accepted.

Discuss

Baidu 如流 discussion group :5425804

Kotlin
1
https://gitee.com/baidu/Rubik.git
git@gitee.com:baidu/Rubik.git
baidu
Rubik
Rubik
main

搜索帮助