Note-51804-5

Token ID: 1

ERC-721 1 Transfers

Metadata

{
  "type": "note",
  "title": "我是如何开发Android App的——历程",
  "tags": [
    "post",
    "Android Dev",
    "Android"
  ],
  "sources": [
    "xlog"
  ],
  "external_urls": [
    "https://lotosbin-4048.xlog.app/Android-Appmd-lc"
  ],
  "date_published": "2022-01-17T10:02:10.979Z",
  "content": "## 我是如何开发Android App的——历程\n#系列 \n#2022-01-06\n#android \n#article/done/published \n\n\n## 历程\n### 阶段一:单个app单个模块\n开始需求很简单,只要一个app就可以了,所有的功能直接放在一个module中。\n```plantuml\ncomponent app\n```\n### 阶段二:单个app多个功能模块\n开始有独立的模块功能,需要定制,一个方案是DynamicFeature\n```plantuml\ncomponent app\ncomponent dynamic_feature_a\ncomponent dynamic_feature_b\ncomponent dynamic_feature_n\ndynamic_feature_a --> app\ndynamic_feature_b --> app\ndynamic_feature_n --> app\n```\n\nDynamicFeature需要应用市场的支持。\n对于需要独立部署的情况不太使用,当然还有https://github.com/iqiyi/Qigsaw 可以自己部署支持动态功能的应用市场。但是部署过于复杂。\n另一个方案就是插件化,插件化有运行时插件化和编译时插件化。\n编译时插件化实现相对简单,只需要动态修改app的依赖就可以了,运行时通过反射获取所有的插件实现并调用对应方法即可。\n\n```plantuml\ncomponent app\ncomponent feature_a\ncomponent feature_b\ncomponent feature_n\napp --> feature_a\napp --> feature_b\napp --> feature_n\n```\n编译不同的插件模块\n:app build.gradle\n```groovy\n\t\ndependencies{\n\tif(useFeature(\"feature_a\")){\n\t\timplementation \":feature_a\"\n\t}\n\tif(useFeature(\"feature_b\")){\n\t\timplementation \":feature_b\"\n\t}\n}\n\n```\n### 阶段三:单个app多个功能模块单个公共模块\n随着功能模块数量的增加,不同模块会有大量重复的库的依赖,并且可能会有版本冲突,\n为了统一工具库的版本和使用,需要统一进行封装。\n所以引入了公共库。\n原则上所有非功能模块核心功能的依赖都要放到公共库中,如网络请求、图片处理、键值存储、数据库等\n并且功能模块不应直接依赖第三方的库,需要经过公共库的封装,方便将来的升级和迁移。\n```plantuml\ncomponent app\ncomponent feature_a\ncomponent feature_b\ncomponent feature_n\napp --> feature_a\napp --> feature_b\napp --> feature_n\ncomponent common\nfeature_a --> common\nfeature_b --> common\nfeature_n --> common\n```\n### 阶段四:功能模块相互依赖\n随着功能模块的增加,功能模块之间也需要有相关的调用,但是功能模块从分层上属于同一层,\n同层之间不应该有直接依赖,否则容易形成循环依赖。\n所以需要引入一个公共功能模块(services)或者叫服务总线,\n所有功能模块通过实现servcies中的接口向其他模块提供服务。\n公共模块和公共功能模块这里一起作为Framework\n```plantuml\npackage apps{\n\tcomponent app\n}\npackage features{\ncomponent feature_a\ncomponent feature_b\ncomponent feature_n\n}\napp --> feature_a\napp --> feature_b\napp --> feature_n\n\npackage framework{\n\tcomponent common\n\n\tcomponent services {\n\t\tcomponent feature_a_service\n\t\tcomponent feature_b_service\n\t\tcomponent feature_n_service\n\t}\n}\nfeatures --> common\nfeature_a --> feature_a_service\nfeature_b --> feature_b_service\nfeature_n --> feature_n_service\n```\n\n关于模块间公开服务调用还有另一种方式,就是每个功能模块单独定义一个公开服务的组件给其他模块调用,但是容易造成依赖关系指数级复杂,所以采用将所有模块的公开服务统一管理的方式\n\n```plantuml\ncomponent feature_a\ncomponent feature_a_service\nfeature_a --|> feature_a_service\n\ncomponent feature_b\ncomponent feature_b_service\nfeature_b --|> feature_b_service\n\ncomponent feature_n\ncomponent feature_n_service\nfeature_n --|> feature_n_service\n\nfeature_a --> feature_b_service\nfeature_b --> feature_a_service\nfeature_n --> feature_a_service\nfeature_n --> feature_b_service\n\n```\n\n### 阶段五:专注功能\n将功能注册到市场,app自动发现功能\n```plantuml\n\npackage framework{\n\tpackage apps{\n\t\tcomponent app\n\t}\n\tcomponent common\n\n\tcomponent services {\n\t\tcomponent feature_a_service\n\t\tcomponent feature_b_service\n\t\tcomponent feature_n_service\n\t}\n}\n\npackage features{\ncomponent feature_a\ncomponent feature_b\ncomponent feature_n\n}\nfeatures --> common\n\napp --> feature_a\napp --> feature_b\napp --> feature_n\n\nfeature_a --> feature_a_service\nfeature_b --> feature_b_service\nfeature_n --> feature_n_service\n```",
  "attributes": [
    {
      "value": "Android-Appmd-lc",
      "trait_type": "xlog_slug"
    }
  ]
}