小记:这个问题从上周就遇到了,无奈小朋友刚刚降生晚上闹睡不好,白天又要去考驾照,心碎。今天费了一个早上的时间终于成功跳转了,心情释然。
写在前面
本篇将介绍组件化过程中??榧涞耐ㄐ胖?-ARouter的基本配置跳转以及遇到的坑
配置如下
- 在使用路由的module的gradle中添加如下代码(base可以不添加)
android {
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [ moduleName : project.getName() ]
}
}
}
}
dependencies {//尽量引用最新版本
compile 'com.alibaba:arouter-api:1.2.4'
annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
...
}
- 宿主app必须依赖所有使用路由的module,使用路由的module间不用相互依赖
(如:modue_A是宿主APP,module_B和module_C之间有相互跳转的操作,则只需在宿主module_A的gradle中配置compile project(':module_B')和compile project(':module_C'))
- 自定义Application中初始化ARouter
if (isDebug()) { // 这两行必须写在init之前,否则这些配置在init过程中将无效
ARouter.openLog(); // 打印日志
ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
}
ARouter.init(mApplication); // 尽可能早,推荐在Application中初始化
- 路由跳转(切记路径格式)
public class Router {
/**
* bilibili 闪屏界面
*/
public static final String BILIBILI_SPLASH = "/bilibili/splash";
}
ARouter.getInstance().build(BILIBILI_SPLASH).navigation();
@Route(path = BILIBILI_SPLASH)
public class SplashActivity extends Activity {
}
踩坑
深坑啊,哭的心都有了,
12-14 11:08:49.747 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: ARouter openLog[ ]
12-14 11:08:49.747 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: ARouter openDebug[ ]
12-14 11:08:49.747 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: ARouter init start.[ ]
12-14 11:08:49.757 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: Run with debug mode or new install, rebuild router map.[ ]
12-14 11:08:49.757 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: VM with name 'Android' has multidex support
12-14 11:08:49.757 23546-23546/com.example.zhangtuo.learndeme E/ARouter::: InstantRun support error, com.android.tools.fd.runtime.Paths
12-14 11:08:49.757 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: Thread production, name is [ARouter task pool No.1, thread No.1][ ]
12-14 11:08:49.777 23546-23546/com.example.zhangtuo.learndeme D/ARouter::: Filter 3 classes by packageName <com.alibaba.android.arouter.routes>
12-14 11:08:49.777 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: Find router map finished, map size = 3, cost 24 ms.[ ]
12-14 11:08:49.777 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: Load root element finished, cost 5 ms.[ ]
12-14 11:08:49.777 23546-23546/com.example.zhangtuo.learndeme D/ARouter::: LogisticsCenter has already been loaded, GroupIndex[1], InterceptorIndex[0], ProviderIndex[2][ ]
12-14 11:08:49.787 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: ARouter init success![ ]
12-14 11:08:49.787 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::No postcard![ ]
12-14 11:08:49.787 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::No postcard![ ]
12-14 11:08:49.787 23546-23546/com.example.zhangtuo.learndeme D/ARouter::: The group [arouter] starts loading, trigger by [/arouter/service/interceptor][ ]
12-14 11:08:49.787 23546-23546/com.example.zhangtuo.learndeme D/ARouter::: The group [arouter] has already been loaded, trigger by [/arouter/service/interceptor][ ]
12-14 11:08:49.787 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: Thread production, name is [ARouter task pool No.1, thread No.2][ ]
12-14 11:08:49.787 23546-23546/com.example.zhangtuo.learndeme I/ARouter::: ARouter init over.[ ]
12-14 11:08:49.957 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::No postcard![ ]
12-14 11:08:49.957 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::No postcard![ ]
12-14 11:08:57.987 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::No postcard![ ]
12-14 11:08:57.987 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::No postcard![ ]
12-14 11:08:57.987 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::There is no route match the path [/bilibili/splash], in group [bilibili][ ]
12-14 11:08:58.007 23546-23546/com.example.zhangtuo.learndeme W/ARouter::: ARouter::No postcard![ ]
初始化成功了,但是遇到There is no route match the path [/bilibili/splash], in group [bilibili][ ] ,百思不得骑姐
这是因为:宿主app必须依赖所有使用路由的module,使用路由的module间不用相互依赖
拓展使用
参考链接:https://github.com/alibaba/ARouter