一直报错,找不到路径
首先先module 里面配置,当前项目是kotlin写的
- implementation "com.alibaba:arouter-api:$rootProject.arouterVersion"
- kapt "com.alibaba:arouter-compiler:$rootProject.arouterProcessorVersion"
- ext{
- arouterVersion ='1.5.2'
- arouterProcessorVersion ='1.5.2'
- }
- defaultConfig {
- kapt {
- arguments {
- arg("AROUTER_MODULE_NAME", project.getName())
- }
- }
- }
在application里面初始化
- override fun onCreate() {
- super.onCreate()
- mInstance = this
- initRouter(this)
- }
-
- fun initRouter(application: Application?) {
- if (BuildConfig.DEBUG) {
- ARouter.openLog()
- ARouter.openDebug()
- }
- ARouter.init(application)
- }
配置总路径,全部放RouteUtils
- object RouteUtils {
- const val Book_Activity_Main = "/main/MainActivity"
- }
通过注解的方式绑定Activity
- @Route(path = RouteUtils.Book_Activity_Main, name = "主页")
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- }
- }
最后启动的时候一直提示 There is no route match the path
原因是app的主项目里面没有
- implementation "com.alibaba:arouter-api:$rootProject.arouterVersion"
- kapt "com.alibaba:arouter-compiler:$rootProject.arouterProcessorVersion"
module里面和主项目都需要配置,官网的文档没有强调这一点
主项目和moudle都需要配置
主项目和moudle都需要配置
主项目和moudle都需要配置