ARouter使用随记

 

官方文档地址

 

其他配置

1.创建一个config.gradle

复制代码
ext{
    isDebug = false //false:作为Lib集成存在, true:作为application组件存在

    android = [
            compileSdkVersion : 28,
            minSdkVersion :19,
            targetSdkVersion :27,
            versionCode :1,
            versionName :"1.0",
    ]
    libsVersion=[
            // App dependencies version
            supportVersion = "28.0.0",
            glideVersion = "4.7.1",
            retrofitVersion ="2.5.0",
            okhttpVersion = "3.8.0",
    ]
    dependencies = [
            //android 官方库
            "appcompat-v7"                   : "com.android.support:appcompat-v7:$rootProject.supportVersion",
            "support-v4"                     : "com.android.support:support-v4:$rootProject.supportVersion",
            "design"                         : "com.android.support:design:$rootProject.supportVersion",
            "annotations"                    : "com.android.support:support-annotations:$rootProject.supportVersion",
            "gson"                           : "com.google.code.gson:gson:2.6.2",
            //路由通讯
            "arouter-api"                    : "com.alibaba:arouter-api:1.4.1",
            "arouter-compiler"               : "com.alibaba:arouter-compiler:1.2.2",
    ]
}
复制代码

Project  gradle引用

apply from:"config.gradle"

2.module  gradle配置

复制代码
def isDebug = rootProject.ext.isDebug
def configs = rootProject.ext.android
def librarys = rootProject.ext.dependencies

if(isDebug){
    apply plugin: 'com.android.application'
}else {
    apply plugin: 'com.android.library'
}
android {
    compileSdkVersion configs.compileSdkVersion

    defaultConfig {
        minSdkVersion configs.minSdkVersion
        targetSdkVersion configs.targetSdkVersion
        versionCode configs.versionCode
        versionName configs.versionName

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        if (isDebug) {
            applicationId "xx.xx.xx"
        }

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [AROUTER_MODULE_NAME: project.getName()]
            }
        }
    }

    sourceSets {
        main {
            //控制两种模式下的资源和代码配置情况
            if (isDebug) {
                manifest.srcFile 'src/main/debug/AndroidManifest.xml'
            } else {
                manifest.srcFile 'src/main/AndroidManifest.xml'
                //集成开发模式下排除debug文件夹中的所有Java文件
                java {
                    exclude 'debug/**'
                }
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}
复制代码

debug下的

作为lib时的

 

 

解决错误:InstantRun support error, com.android.tools.fd.runtime.Paths 以及 There is no route match the path 

每个需要路由操作的module 都需要添加

implementation 'com.alibaba:arouter-api:x.x.x'
annotationProcessor 'com.alibaba:arouter-compiler:x.x.x'

app gradle配置(将需要路由操作的module都依赖到app的module下)

复制代码
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    //noinspection GradleCompatible
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(':基类module')

    if (!isDebug){
        implementation project(':login')
        implementation project(':test')
    }
}
复制代码

 

posted @   西瓜皮不甜  阅读(2269)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!
点击右上角即可分享
微信分享提示