1 Star 0 Fork 8

homeleaf / MVVMFrameComponent

forked from Jenly / MVVMFrameComponent 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MVVMFrameComponent

Image

Download API License Blog QQGroup

基于 MVVMFrame 框架为核心基础库构建的组件化方案

主要使用的核心技术

  • JetPack(Lifecycle,LiveData,ViewModel,Room)
  • Dagger
  • DataBinding
  • Retrofit
  • OkHttp
  • Glide
  • Kotlin coroutines
  • ARouter

架构

MVVMFrameComponent 组件化架构图分层如下:

Architecture

因为组件化的核心基础库是基于 MVVMFrame,这里贴出 MVVMFrame 的架构图如下:

Architecture

浅谈组件化

  1. 什么是组件化?

组件化简单概括就是把一个功能完整的 App模块 拆分成多个子模块, 让每个子模块可以独立编译和运行, 也可以作为 library 合并到宿主App组成一个完整的 App进行编译和运行。每个模块即可以不相互依赖,又可以相互交互。

  1. 为什么要组件化?

当一个项目随着时间的推移,需求不断的变更与迭代。各个模块也会变的相对复杂。维护难度也会随之增加,时间久了,可能会引起一些新的问题。这时我们就需要组件化。

  1. 组件化的优势是什么?

当一个App使用组件化开发方案时,主要的优势有:组件化拆分各个模块后,每个子模块都可以独立编译和运行,这样在开发调测某个模块时,可以大大提高编译速度和开发效率。多人开发时,每个人负责独立的模块,更有利于多人团队协作开发。并且各个模块之间的代码边界相对清晰,更易于后期维护。

MVVMFrameComponent 组件化方案

MVVMFrameComponent = MVVMFrame + Component。即 MVVMFrameComponent 采用 MVVM 模式架构的组件化方案。

工程各个 Module 相关说明

app

宿主App:当各个子 Module 作为 library 时,则可将所有组件集成到 宿主App 中。此时 宿主App 则是一个拥有所有组件功能集合的完整的App。

common-base

组件化公共基础库:主要包含 MVVMFrame 快速开发框架,和作为组件化的一些公共的核心基础库,方便快速构建组件化 Project

common-res

组件化公共资源库:主要方便统一管理各个 Module 中的一些公共资源相关。

module-joke

一个简单的笑话功能模块:主要用来展示基于 MVVMFrame 来实现组件化开发,作为组件化开发的 Module 实现示例之一。

module-news

一个简单的新闻功能模块:主要用来展示基于 MVVMFrame 来实现组件化开发,作为组件化开发的 Module 实现示例之一。

其他

特别说明

Project -> build.gradle 内的自定义变量 isBuildModule

自定义变量 isBuildModule 来统一管理各个子 module 方便在 applicationlibrary 之间进行切换

isBuildModule = true 时,表示 各个子 moduleapplication ,即 module 可独立运行 当 isBuildModule = false 时,表示 各个子 modulelibrary ,即 module 作为 library 合并到 宿主App

Project -> module-build.gradle

组件化子 module 通用 build.gradle ,方便统一管理

根据 isBuildModule 来统一管理各个子 moduleapplicationlibrary 之间切换

关于 MVVMFrame

因为 MVVMFrameComponent 的核心基础库是基于 MVVMFrame 的,所以需要对 MVVMFrame 有一定的了解,才能在使用 MVVMFrameComponent 时更加得心应手, 这里不再特意介绍 MVVMFrame 相关的使用,具体介绍你可以直接查看 MVVMFrame

示例

关于各组件/模块共用 Application 初始化

在每一个子模块,写一个IComponentApp的实现类,实现各个子模块共用 Application,示例如下:

//这是app中的示例
class AppComponentApp: IComponentApp {

    override fun onCreate(app: BaseApp) {
        DaggerAppMainComponent.builder()
            .appComponent(app.appComponent)
            .build()
            .inject(app)

    }

}

Manifest 中配置 meta-data 对应的IComponentApp实现类,示例如下 :

        <meta-data android:name="com.king.mvvm.component.app.AppComponentApp"
            android:value="ComponentApp"/>

更多使用详情,请查看app中的源码使用示例

赞赏

如果你喜欢MVVMFrameComponent,或感觉MVVMFrameComponent帮助到了你,可以点右上角“Star”支持一下,你的支持就是我的动力,谢谢 :smiley:

你也可以扫描下面的二维码,请作者喝杯咖啡 :coffee:

关于我

Name: Jenly

Email: jenly1314#gmail.com / jenly1314#vip.qq.com

CSDN: jenly121

CNBlogs: jenly

GitHub: jenly1314

Gitee: jenly1314

加入QQ群: 20867961

The MIT License (MIT) Copyright (c) 2020 Jenly Yu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于 MVVMFrame 框架 采用 JetPack (Lifecycle,LiveData,ViewModel,Room) + Dagger + DataBinding + Retrofit + OkHttp + Glide + Kotlin coroutines + ARouter等 为核心基础库构建的组件化方案 展开 收起
Kotlin
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Kotlin
1
https://gitee.com/homeleaf/MVVMFrameComponent.git
git@gitee.com:homeleaf/MVVMFrameComponent.git
homeleaf
MVVMFrameComponent
MVVMFrameComponent
master

搜索帮助