ARouter使用随记

2019/03/04 12:47
阅读数 473

 

官方文档地址

 

其他配置

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')
    }
}

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部