ARouter是阿里团队开源的一款提供路由功能的中间件,项目地址:https://github.com/alibaba/ARouter。
路由功能对android组件化开发的模块解耦有重要意义,通过本文我们可以先了解ARouter的使用方法以及使用中的常见问题。
使用方法
一、在提供路由功能的模块的build.gradle文件中,添加下述信息
android {
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [ moduleName : project.getName() ]
}
}
}
}
dependencies {
// 替换成最新版本, 需要注意的是api
// 要与compiler匹配使用,均使用最新版可以保证兼容
compile 'com.alibaba:arouter-api:x.x.x'
annotationProcessor 'com.alibaba:arouter-compiler:x.x.x'
...
}
当前的最新版本在github首页展示,如下图
image.png
二、在提供路由功能的模块中,在支持路由的页面上添加注解(必选)。这里的路径需要注意的是至少需要有两级,/xx/xx
@Route(path &