美文网首页我爱编程
使用Arouter协助组件化开发

使用Arouter协助组件化开发

作者: 走在冷风中吧 | 来源:发表于2018-05-31 21:42 被阅读99次

前言: 当项目很庞大的时候, 为更方便的进行小组成员开发,减小冲突,需要采用组件式开发, 配合阿里的Arouter, 可以更方便高效的设置页面间的路由.
GitHub地址:
https://github.com/alibaba/ARouter


组件化中ARouter使用配置注意事项:

  1. 在每一个modlue!!!!!下都要进行如下配置
    build.gradle文件中:
    defaultConfig {
     ......
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [moduleName: project.getName()]
            }
        }
    }
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    kapt 'com.alibaba:arouter-compiler:1.1.3'
  或者:
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    annotationProcessor 'com.alibaba:arouter-compiler:1.1.3'

注意: 项目中如果引用了kotlin的话 一定!!要使用:
kapt 'com.alibaba:arouter-compiler:1.1.3' 否则会报W/ARouter::: ARouter::There is no route match the path [/xxx/xxx], in group [xxx][ ]"的错, 就因为这个问题浪费了一下午时间....


  1. 多个Module的使用:
    组件化运行主模块时, 需要将别的各个module的build.gradle中的
    添加apply plugin: 'com.android.library', 并且在主模块中引入依赖:
    例如某个module叫做moduleA,
    则需要配置: 'compile project(path: ':modlueA')'
    否则的话 也会报W/ARouter::: ARouter::There is no route match the path [/xxx/xxx], in group [xxx][ ]"的错, 哭哭~~~~~

  1. 配置完之后就可以简单使用了:
//使用route注解添加路由
@Route(path = "/moduleA/main3")
public class Main3Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
       }

}

在一个activity调用这个路由即可跳转到Main3Activity页面

    fun module2(view: View) {
        ARouter.getInstance().build("/moduleA/main3").navigation()
    }

相关文章

网友评论

    本文标题:使用Arouter协助组件化开发

    本文链接:https://www.haomeiwen.com/subject/vfscsftx.html