简介
- 什么是路由?
说简单点就是映射页面跳转关系的,当然它也包含跳转相关的一切功能。 - 为什么需要路由?
在一些复杂的业务场景下(比如电商),灵活性比较强,很多功能都是运营人员动态配置的,比如下发一个活动页面,我们事先并不知道具体的目标页面,但如果事先做了约定,提前做好页面映射,便可以自由配置。
随着业务量的增长,客户端必然随之膨胀,开发人员的工作量越来越大,比如64K问题
协作开发问题。App一般都会走向组件化、插件化的道路,而组件化、插件化的前提就是解耦,那么我们首先要做的就是解耦页面之间的依赖关系。
简化代码。数行跳转代码精简成一行代码 - Arouter简介?
ARouter是阿里巴巴开源的Android平台中对页面、服务提供路由功能的中间件,提倡的是简单且够用。
GitHub:https://github.com/alibaba/ARouter - Arouter优势?
支持直接解析标准URL进行跳转,并自动注入参数到目标页面中支持多模块工程使用
支持添加多个拦截器,自定义拦截顺序
支持依赖注入,可单独作为依赖注入框架使用
支持InstantRun
支持MultiDex(Google方案)映射关系按组分类、多级管理,按需初始化
支持用户指定全局降级与局部降级策略
页面、拦截器、服务等组件均自动注册到框架
支持多种方式配置转场动画
支持获取Fragment
支持Kotlin以及混编 - Calces框架简介
Android构建工具包,这个工具的主旨是使用脚本自动处理机械化的重复劳动,让开发者专注更有价值的工作。 目前提供自动组件化控制与屏幕适配插件。
组件化构建Gradle插件
插件包的名字叫: component,其中提供了两个组件化辅助插件,分别叫calces.appconfig和calces.modules。 主要的功能是: 提供Gradle配置App依赖的组件、配置组件是否能单独运行、实现多个依赖不同模块的App同时构建等。
屏幕适配插件 组件包的名字叫: screen,其中提供了calces.screen插件
主要功能是: 根据设计稿与配置,自动生成smallestWidth适配文件,让你从此不需要再关注屏幕适配。 - 常用API
https://github.com/alibaba/ARouter/blob/master/README_CN.md
https://github.com/Tangpj/calces-gradle-plugin#功能介绍
使用
1.模块化:
每个module都是一个library不能独立运行
2.组件化:
每个module都是一个组件(application)可以独立运行->模块化测试;
按照业务拆分->商城;用户;社区;资讯
3.模块化与组件化的区别;
模块化不能独立运行组件化可以独立运行
4.Calces配置组件化:
自动化构建module-.组合不同应用程序
5.Calces如何使用:
官网地址:https://github.com/Tangpj/calces-gradle-plugin
a.添加calces插件:
plugins {
id “calces.modules” version “1.0.11”
}
b.修改module 下gradle文件插件
c,项目下的gradle文件中配置项目中的组件
project的gradle配置
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id "calces.appconfig" version "1.0.11"
}
//calces组件化配置
appConfig{
//debug测试模式->开发阶段为true->各个子模块单独运行测试
debugEnable true
//组件化架构中,第三层不同业务路基组件
apps{
app{
modules ':news',':user'
}
}
modules{
//新闻资讯
news {
name ':news'
mainActivity ".MainActivity"
applicationId "com.example.news"
isRunAlone false
//是否可以单独运行
}
//用户
user {
name ':user'
mainActivity ".MainActivity"
applicationId "com.example.user"
isRunAlone false
//是否可以单独运行
}
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
module的gradle配置
apply plugin: 'calces.modules'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}