ARouter基本配置踩坑

小記:這個(gè)問題從上周就遇到了,無奈小朋友剛剛降生晚上鬧睡不好,白天又要去考駕照,心碎。今天費(fèi)了一個(gè)早上的時(shí)間終于成功跳轉(zhuǎn)了,心情釋然。

寫在前面

本篇將介紹組件化過程中模塊間的通信助手--ARouter的基本配置跳轉(zhuǎn)以及遇到的坑

配置如下

  1. 在使用路由的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'
    ...
}
  1. 宿主app必須依賴所有使用路由的module,使用路由的module間不用相互依賴
    (如:modue_A是宿主APP,module_B和module_C之間有相互跳轉(zhuǎn)的操作,則只需在宿主module_A的gradle中配置compile project(':module_B')和compile project(':module_C'))
  2. 自定義Application中初始化ARouter
if (isDebug()) {           // 這兩行必須寫在init之前,否則這些配置在init過程中將無效
    ARouter.openLog();     // 打印日志
    ARouter.openDebug();   // 開啟調(diào)試模式(如果在InstantRun模式下運(yùn)行,必須開啟調(diào)試模式!線上版本需要關(guān)閉,否則有安全風(fēng)險(xiǎn))
}
ARouter.init(mApplication); // 盡可能早,推薦在Application中初始化
  1. 路由跳轉(zhuǎn)(切記路徑格式)
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][ ] ,百思不得騎姐
這是因?yàn)椋核拗鱝pp必須依賴所有使用路由的module,使用路由的module間不用相互依賴

拓展使用

參考鏈接:https://github.com/alibaba/ARouter

over

悶騷代碼男,碼字不易,請(qǐng)?zhí)鹉愕男∈郑c(diǎn)個(gè)贊唄~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容