探索Android路由框架-ARouter

作者: wxyass 分类: Android 发布时间: 2018-07-03 20:44

转载:
https://github.com/alibaba/ARouter
探索Android路由框架-ARouter
探索Android路由框架-ARouter之基本使用(一)
Android 路由框架ARouter最佳实践

出现错误:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.RuntimeException: ARouter::Compiler >>> No module name, for more information, look at gradle log.


解决:
添加代码 javaCompileOptions

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        applicationId "tsingtaopad.et.arouterdemo"
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

    }

跳转Fragment

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) { // 普通Fragment路由跳转
        //获取Fragment 实例
        Fragment fragment = (Fragment) ARouter.getInstance().build( "/com/FragmentOne" ).navigation();

        //添加Fragment
        FragmentManager fragmentManager = getSupportFragmentManager() ;
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction() ;
        fragmentTransaction.add(  R.id.fragmentLayout , fragment ) ;
        fragmentTransaction.commit();
    }
});

代码下载

其他路由
https://github.com/yifei8/ABridge
https://github.com/wenzhonghu/MyRouter
https://github.com/yifei8/ARetrofit
https://github.com/chenenyu/Router

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注