Android Arouter多Module组件项目中 出现“There is no route match the path”问题解决

文章主要介绍了在AndroidArouter多Module组件化项目中遇到‘Thereisnoroutematchthepath’错误时的解决方法,重点在于检查和配置各Module的build.gradle文件,确保AROUTER_MODULE_NAME参数正确设置。对于Java和Kotlin混编的情况,强调了需要使用Kotlin的kapt配置来保证路由编译正常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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配置后可以跳转/实例成功

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值