kotlin实用ARouter:Compiler An exception is encountered和There is no route match

kotlin/java混合开发接入ARouter遇到的问题Compiler An exception is encountered, [These no module name, at 'build. 以及There is no route match the path [/xxx/xxxx], in group [\xxx][ ]

当前ARouter的版本

模块 arouter-api arouter-compiler arouter-register arouter-idea-plugin
最新版本 1.5.2 1.5.2 1.0.2 13k

项目基本结构:

lib_common作为底层库,是所有仓库底层的依赖

Compiler An exception is encountered

报错

修正

问题原因ARoute 未完全兼容Kotlin - Java混编的问题导致,需要Kotlin、Java各写一份,希望官方未来的版本早日兼容。查这个问题耗费了挺多时间😭😭

问题源解,参考自:

报错信息

vbnet 复制代码
ARouter::Compiler An exception is encountered, [These no module name, at 'build.gradle', like :
  android {
      defaultConfig {
          ...
          javaCompileOptions {
              annotationProcessorOptions {
                  arguments = [AROUTER_MODULE_NAME: project.getName()]
              }
          }
      }
  }
  ]
​
Execution failed for task ':settings:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)
​

刚开始报错配置如下:

Base Module:

bash 复制代码
plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-kapt'
}
​
android {
  defaultConfig {
    // ...
    javaCompileOptions {
            annotationProcessorOptions {
                arguments = [AROUTER_MODULE_NAME: project.getName()]
            }
        }
  }
}
​
dependencies {
    api 'com.alibaba:arouter-api:1.5.2'
    kapt 'com.alibaba:arouter-compiler:1.5.2'
}

Other Modules:

bash 复制代码
plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-kapt'
}
​
android {
  defaultConfig {
    // ...
    javaCompileOptions {
            annotationProcessorOptions {
                arguments = [AROUTER_MODULE_NAME: project.getName()]
            }
        }
  }
}
​
dependencies {
    api project(':base')
    kapt 'com.alibaba:arouter-compiler:1.5.2'
}

总是提示我没有配置【javaCompileOptions】这部分,但是我明明配置了,换成kotlin版的也不行

项目是Kotlin项目,有部分Java类,build.gradle脚本是Grovey语言,并非是KTS

javascript 复制代码
kapt {
    arguments {
        arg("AROUTER_MODULE_NAME", project.getName())
    }
}

查找相关问题后,类似的解决方案是Java和Kotlin两个版本都配置;于是两个版本都一起配置上去了,居然就行了,这坑真是深,接入的版本是1.5.2😱😱😱

javascript 复制代码
android {
      defaultConfig {
          // ...
          javaCompileOptions {
              annotationProcessorOptions {
                  arguments = [AROUTER_MODULE_NAME: project.getName()]
              }
          }
        
          kapt {
              arguments {
                  arg("AROUTER_MODULE_NAME", project.getName())
              }
          }
      }
}
​

继续报错:There is no route match the path [/xxx/xxxx], in group [\xxx][ ]

但是,在我配置完上述内容后,我发现我的项目依然存在问题, 路由路劲找不到🥶🥶

过滤到的ARouter日志是:

ini 复制代码
2023-10-04 21:57:00.047  8388-8388  ARouter::               top.iqqcode.viewcustoms              W  ARouter::There is no route match the path [/animations/ModuleAnimationMainActivity], in group [animations][ ] 

一一排除了官方给出的可能性,我的配置没有任何问题:

github.com/alibaba/ARo...

"W/ARouter::: ARouter::There is no route match the path [/xxx/xxx], in group [xxx](#"W/ARouter::: ARouter::There is no route match the path [/xxx/xxx], in group xxx" "#")"

一、通常来说这种情况是没有找到目标页面,目标不存在

二、如果这个页面是存在的,那么您可以按照下面的步骤进行排查

  • 检查目标页面的注解是否配置正确,正确的注解形式应该是 (@Route(path="/test/test"), 如没有特殊需求,请勿指定group字段,废弃功能);不同的模块间一级路径名称要个不相同,如login模块/login/LoginActivity,而user模块/user/UserInfoActivity
  • 检查目标页面所在的模块的gradle脚本中是否依赖了 arouter-compiler sdk (需要注意的是,要使用apt依赖,而不是compile关键字依赖)
  • 检查编译打包日志,是否出现了形如 ARouter::�Compiler >>> xxxxx 的日志,日志中会打印出发现的路由目标
  • 启动App的时候,开启debug、log(openDebug/openLog), 查看映射表是否已经被扫描出来,形如 D/ARouter::: LogisticsCenter has already been loaded, GroupIndex[4],GroupIndex > 0

排除法确认上述配置均正确


Kapt解决

在引用**arouter-compiler**时,Kotlin的项目或者Kotlin-Java混编的项目,必须使用 **kapt**来依赖,否则会出现 "W/ARouter::: ARouter::There is no route match the path [/xxx/xxx], in group [xxx](#"W/ARouter::: ARouter::There is no route match the path [/xxx/xxx], in group xxx" "#")"

将lib_common模块对config.gradle的arouter-compiler依赖引用由API的方式换为 kapt 即可

检查目标页面所在的模块的gradle脚本中是否依赖了 arouter-compiler sdk (需要注意的是,要使用 kapt 依赖,而不是compile或者implementation关键字依赖) ,即无论哪个模块需要路由跳转,双方的modle都要引入annotationProcessor 'com.alibaba:arouter-compiler:x.x.x'


【参考文章】

1\]. Android 手把手带你搭建一个组件化项目架构. [juejin.cn/post/703395...](https://juejin.cn/post/7033954652315975688?searchId=20231004133953C45B44465E3AD7FBF44B#heading-8 "https://juejin.cn/post/7033954652315975688?searchId=20231004133953C45B44465E3AD7FBF44B#heading-8") \[2\]. kotlin/java混合开发接入ARouter遇到的问题. [blog.csdn.net/guangdeshis...](https://link.juejin.cn?target=https%3A%2F%2Fblog.csdn.net%2Fguangdeshishe%2Farticle%2Fdetails%2F119787100 "https://blog.csdn.net/guangdeshishe/article/details/119787100") \[3\]. KOTLIN AROUTER THERE IS NO ROUTE MATCH THE PATH IN GROUP. [www.freesion.com/article/953...](https://link.juejin.cn?target=https%3A%2F%2Fwww.freesion.com%2Farticle%2F9534626868%2F "https://www.freesion.com/article/9534626868/")

相关推荐
灯火不休➴9 分钟前
安卓 ContentProvider 详解:跨应用数据共享的核心方案
android
沐怡旸41 分钟前
【底层机制】【Android】Android 系统的启动流程
android
limuyang244 分钟前
【http3/quic】cronet 已经原生集成在Android内啦!还不快来开开眼!
android·http·google
乌萨奇也要立志学C++1 小时前
【Linux】Ext系列文件系统 从磁盘结构到文件存储的原理剖析
android·linux·缓存·1024程序员节
宋发元3 小时前
IPhone 17 Pro Max拍摄专业画质视频教程
android·gradle·iphone
出门吃三碗饭4 小时前
如何在LLM大语言模型上微调来优化数学推理能力?
android·人工智能·语言模型
shaominjin1235 小时前
Android访问OTG文件全解析:从连接到操作的完整指南Android系统访问U盘的实现机制与操作指南
android
游戏开发爱好者88 小时前
HTTPS 内容抓取实战 能抓到什么、怎么抓、不可解密时如何定位(面向开发与 iOS 真机排查)
android·网络协议·ios·小程序·https·uni-app·iphone
Tom4i10 小时前
Android 系统的进程模型
android
介一安全10 小时前
【Frida Android】基础篇9:Java层Hook基础——Hook构造函数
android·网络安全·逆向·安全性测试·frida