Android -Arouter使用说明

1.

app 中 build.gradle中配置

如下

    

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.xutil.xxxx"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        javaCompileOptions{
            annotationProcessorOptions {
                arguments = [AROUTER_MODULE_NAME: project.getName()]
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:27.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    compile 'com.alibaba:arouter-api:1.4.0'
    annotationProcessor  'com.alibaba:arouter-compiler:1.2.1'

}

 

2.主项目的 build.gradle配置如下

 

apply plugin: 'com.alibaba.arouter'
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
      // classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

      classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
        classpath 'com.alibaba:arouter-register:1.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

3.官方链接 https://github.com/alibaba/ARouter

 

Android ARouter 是一个用于实现组件化、模块化开发的路由框架,它提供了一种简单的方式来实现不同组件之间的跳转和通信。 使用 ARouter 的步骤如下: 1. 在项目的 build.gradle 文件中添加依赖: ```groovy implementation 'com.alibaba:arouter-api:x.x.x' annotationProcessor 'com.alibaba:arouter-compiler:x.x.x' ``` 请将 `x.x.x` 替换为最新的版本号。 2. 在需要使用 ARouter 的模块中,创建一个类似于 Application 的类,并在其 `onCreate()` 方法中进行 ARouter 的初始化: ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { ARouter.openLog(); ARouter.openDebug(); } ARouter.init(this); } } ``` 3. 在需要跳转到的目标页面中,使用 `@Route` 注解进行标记,以便 ARouter 进行识别: ```java @Route(path = "/path/to/target") public class TargetActivity extends AppCompatActivity { // ... } ``` 4. 在需要跳转的地方,通过调用 `ARouter.getInstance().build("/path/to/target").navigation()` 来实现页面跳转: ```java ARouter.getInstance().build("/path/to/target").navigation(); ``` 5. 如果需要传递参数,可以使用 `withXxx` 方法来添加参数: ```java ARouter.getInstance() .build("/path/to/target") .withString("key", "value") .navigation(); ``` 通过以上步骤,你就可以在 Android 项目中使用 ARouter 进行页面跳转和参数传递了。当然,ARouter 还提供了其他功能,比如拦截器、URI 跳转等,你可以根据具体需求进行使用。希望对你有所帮助!如果还有其他问题,请继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值