Android Arouter多Module组件项目中 出现“There is no route match the path”问题
出现这个问题不用担心,基本上可以肯定是配置问题
首先检查各个Module组件的build.gradle文件中是否按要求配置
Java配置如下:
plugins {
id 'com.android.library'
}
android {
namespace 'com.xxx.mylibrary'
compileSdk 33
defaultConfig {
minSdk 24
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation project(path: ':appBase')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
annotationProcessor 'com.alibaba:arouter-compiler:1.5.2'
implementation 'com.alibaba:arouter-api:1.5.2'
}
Kotlin配置如下:
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
}
apply plugin: 'kotlin-android'
android {
namespace 'com.xxx.mylibrary'
compileSdk 33
defaultConfig {
minSdk 24
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
kapt {
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation project(path: ':appBase')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
kapt 'com.alibaba:arouter-compiler:1.2.2'
implementation 'com.alibaba:arouter-api:1.5.2'
}
Java、Kotlin混编
Java、Kotlin混编配置请一定要留意了,请一定要设置Kotlin的配置,不然你会一直找不到路径,这一点我已经亲测
如图如果你配置了 org.jetbrains.kotlin.kapt,即使你的Activity、Fragment都是Java代码编写,也请按照Kotlin配置
具体原因没去细究,但是按Kotlin配置后可以跳转/实例成功