{"id":13774631,"url":"https://github.com/alibaba/ARouter","last_synced_at":"2025-05-11T06:33:38.047Z","repository":{"id":38360019,"uuid":"76413186","full_name":"alibaba/ARouter","owner":"alibaba","description":"💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)","archived":false,"fork":false,"pushed_at":"2023-09-11T06:07:41.000Z","size":26589,"stargazers_count":14478,"open_issues_count":134,"forks_count":2613,"subscribers_count":366,"default_branch":"develop","last_synced_at":"2025-04-23T17:18:47.659Z","etag":null,"topics":["android","componentization","dependency-injection","interceptor","navigation","router"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alibaba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-12-14T01:27:49.000Z","updated_at":"2025-04-23T01:41:30.000Z","dependencies_parsed_at":"2023-10-20T16:37:32.774Z","dependency_job_id":null,"html_url":"https://github.com/alibaba/ARouter","commit_stats":{"total_commits":217,"total_committers":26,"mean_commits":8.346153846153847,"dds":"0.17972350230414746","last_synced_commit":"60e6b63c6d30beaaf46a6c1b031d49e0b952babc"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2FARouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2FARouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2FARouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2FARouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alibaba","download_url":"https://codeload.github.com/alibaba/ARouter/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253528415,"owners_count":21922623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","componentization","dependency-injection","interceptor","navigation","router"],"created_at":"2024-08-03T17:01:28.865Z","updated_at":"2025-05-11T06:33:33.035Z","avatar_url":"https://github.com/alibaba.png","language":"Java","readme":"```\n    A framework for assisting in the renovation of Android app componentization\n```\n\n[中文文档](https://github.com/alibaba/ARouter/blob/master/README_CN.md)\n\n##### [![Join the chat at https://gitter.im/alibaba/ARouter](https://badges.gitter.im/alibaba/ARouter.svg)](https://gitter.im/alibaba/ARouter?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge) [![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\n---\n\n#### Lastest version\n\nmodule|arouter-api|arouter-compiler|arouter-register|arouter-idea-plugin\n---|---|---|---|---\nversion|[![Download](https://maven-badges.herokuapp.com/maven-central/com.alibaba/arouter-api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.alibaba/arouter-api)|[![Download](https://maven-badges.herokuapp.com/maven-central/com.alibaba/arouter-compiler/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.alibaba/arouter-compiler)|[![Download](https://maven-badges.herokuapp.com/maven-central/com.alibaba/arouter-register/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.alibaba/arouter-register)|[![as plugin](https://img.shields.io/jetbrains/plugin/d/11428-arouter-helper.svg)](https://plugins.jetbrains.com/plugin/11428-arouter-helper)\n\n#### Demo\n\n##### [Demo apk](https://github.com/alibaba/ARouter/blob/develop/demo/arouter-demo-1.5.2.apk)、[Demo Gif](https://raw.githubusercontent.com/alibaba/ARouter/master/demo/arouter-demo.gif)\n\n#### I. Feature\n1. **Supports direct parsing of standard URLs for jumps and automatic injection of parameters into target pages**\n2. **Support for multi-module**\n3. **Support for interceptor**\n4. **Support for dependency injection**\n5. **InstantRun support**\n6. **MultiDex support**\n7. Mappings are grouped by group, multi-level management, on-demand initialization\n8. Supports users to specify global demotion and local demotion strategies\n9. Activity, interceptor and service can be automatically registered to the framework\n10. Support multiple ways to configure transition animation\n11. Support for fragment\n12. Full kotlin support (Look at Other#2)\n13. **Generate route doc support**\n14. **Provide IDE plugin for quick navigation to target class**\n15. Support Incremental annotation processing\n16. Support register route meta dynamic.\n\n#### II. Classic Case\n1. Forward from external URLs to internal pages, and parsing parameters\n2. Jump and decoupling between multi-module\n3. Intercept jump process, handle login, statistics and other logic\n4. Cross-module communication, decouple components by IoC\n\n#### III. Configuration\n1. Adding dependencies and configurations\n    ``` gradle\n    android {\n        defaultConfig {\n            ...\n            javaCompileOptions {\n                annotationProcessorOptions {\n                    arguments = [AROUTER_MODULE_NAME: project.getName()]\n                }\n            }\n        }\n    }\n\n    dependencies {\n        // Replace with the latest version\n        compile 'com.alibaba:arouter-api:?'\n        annotationProcessor 'com.alibaba:arouter-compiler:?'\n        ...\n    }\n    // Old version of gradle plugin (\u003c 2.2), You can use apt plugin, look at 'Other#1'\n    // Kotlin configuration reference 'Other#2'\n    ```\n\n2. Add annotations\n    ``` java\n    // Add annotations on pages that support routing (required)\n    // The path here needs to pay attention to need at least two levels : /xx/xx\n    @Route(path = \"/test/activity\")\n    public class YourActivity extend Activity {\n        ...\n    }\n    ```\n\n3. Initialize the SDK\n    ``` java\n    if (isDebug()) {           // These two lines must be written before init, otherwise these configurations will be invalid in the init process\n        ARouter.openLog();     // Print log\n        ARouter.openDebug();   // Turn on debugging mode (If you are running in InstantRun mode, you must turn on debug mode! Online version needs to be closed, otherwise there is a security risk)\n    }\n    ARouter.init(mApplication); // As early as possible, it is recommended to initialize in the Application\n    ```\n\n4. Initiate the routing\n    ``` java\n    // 1. Simple jump within application (Jump via URL in 'Advanced usage')\n    ARouter.getInstance().build(\"/test/activity\").navigation();\n\n    // 2. Jump with parameters\n    ARouter.getInstance().build(\"/test/1\")\n                .withLong(\"key1\", 666L)\n                .withString(\"key3\", \"888\")\n                .withObject(\"key4\", new Test(\"Jack\", \"Rose\"))\n                .navigation();\n    ```\n\n5. Add confusing rules (If Proguard is turn on)\n    ``` \n    -keep public class com.alibaba.android.arouter.routes.**{*;}\n    -keep public class com.alibaba.android.arouter.facade.**{*;}\n    -keep class * implements com.alibaba.android.arouter.facade.template.ISyringe{*;}\n\n    # If you use the byType method to obtain Service, add the following rules to protect the interface:\n    -keep interface * implements com.alibaba.android.arouter.facade.template.IProvider\n\n    # If single-type injection is used, that is, no interface is defined to implement IProvider, the following rules need to be added to protect the implementation\n    # -keep class * implements com.alibaba.android.arouter.facade.template.IProvider\n    ```\n\n6. Using the custom gradle plugin to autoload the routing table\n    ```gradle\n    apply plugin: 'com.alibaba.arouter'\n\n    buildscript {\n        repositories {\n            mavenCentral()\n        }\n\n        dependencies {\n            // Replace with the latest version\n            classpath \"com.alibaba:arouter-register:?\"\n        }\n    }\n    ```\n\n    Optional, use the registration plugin provided by the ARouter to automatically load the routing table(power by [AutoRegister](https://github.com/luckybilly/AutoRegister)). By default, the ARouter will scanned the dex files .\n    Performing an auto-registration via the gradle plugin can shorten the initialization time , it should be noted that the plugin must be used with api above 1.3.0!\n\n7. use ide plugin for quick navigation to target class (Optional)\n\n    Search for `ARouter Helper` in the Android Studio plugin market, or directly download the `arouter-idea-plugin` zip installation package listed in the `Latest version` above the documentation, after installation\n    plugin without any settings, U can find an icon at the beginning of the jump code. (![navigation](https://raw.githubusercontent.com/alibaba/ARouter/develop/arouter-idea-plugin/src/main/resources/icon/outline_my_location_black_18dp.png)) click the icon to jump to the target class that identifies the path in the code.\n\n#### IV. Advanced usage\n1. Jump via URL\n    ``` java\n    // Create a new Activity for monitoring Scheme events, and then directly pass url to ARouter\n    public class SchemeFilterActivity extends Activity {\n        @Override\n        protected void onCreate(Bundle savedInstanceState) {\n            super.onCreate(savedInstanceState);\n\n            Uri uri = getIntent().getData();\n            ARouter.getInstance().build(uri).navigation();\n            finish();\n        }\n    }\n    ```\n\n    AndroidManifest.xml\n    ``` xml\n    \u003cactivity android:name=\".activity.SchemeFilterActivity\"\u003e\n        \u003c!-- Scheme --\u003e\n        \u003cintent-filter\u003e\n            \u003cdata\n                android:host=\"m.aliyun.com\"\n                android:scheme=\"arouter\"/\u003e\n\n            \u003caction android:name=\"android.intent.action.VIEW\"/\u003e\n\n            \u003ccategory android:name=\"android.intent.category.DEFAULT\"/\u003e\n            \u003ccategory android:name=\"android.intent.category.BROWSABLE\"/\u003e\n        \u003c/intent-filter\u003e\n    \u003c/activity\u003e\n    ```\n\n2. Parse the parameters in the URL\n    ``` java\n    // Declare a field for each parameter and annotate it with @Autowired\n    @Route(path = \"/test/activity\")\n    public class Test1Activity extends Activity {\n        @Autowired\n        public String name;\n        @Autowired\n        int age;\n        @Autowired(name = \"girl\") // Map different parameters in the URL by name\n        boolean boy;\n        @Autowired\n        TestObj obj;    // Support for parsing custom objects, using json pass in URL\n\n        @Override\n        protected void onCreate(Bundle savedInstanceState) {\n            super.onCreate(savedInstanceState);\n            ARouter.getInstance().inject(this);\n\n            // ARouter will automatically set value of fields\n            Log.d(\"param\", name + age + boy);\n        }\n    }\n\n    // If you need to pass a custom object, Create a new class(Not the custom object class),implement the SerializationService, And use the @Route annotation annotation, E.g:\n    @Route(path = \"/yourservicegroupname/json\")\n    public class JsonServiceImpl implements SerializationService {\n        @Override\n        public void init(Context context) {\n\n        }\n\n        @Override\n        public \u003cT\u003e T json2Object(String text, Class\u003cT\u003e clazz) {\n            return JSON.parseObject(text, clazz);\n        }\n\n        @Override\n        public String object2Json(Object instance) {\n            return JSON.toJSONString(instance);\n        }\n    }\n    ```\n\n3. Declaration Interceptor (Intercept jump process, AOP)\n    ``` java\n    // A more classic application is to handle login events during a jump so that there is no need to repeat the login check on the target page.\n    // Interceptors will be executed between jumps, multiple interceptors will be executed in order of priority\n    @Interceptor(priority = 8, name = \"test interceptor\")\n    public class TestInterceptor implements IInterceptor {\n        @Override\n        public void process(Postcard postcard, InterceptorCallback callback) {\n            ...\n            // No problem! hand over control to the framework\n            callback.onContinue(postcard);  \n            \n            // Interrupt routing process\n            // callback.onInterrupt(new RuntimeException(\"Something exception\"));      \n\n            // The above two types need to call at least one of them, otherwise it will not continue routing\n        }\n\n        @Override\n        public void init(Context context) {\n            // Interceptor initialization, this method will be called when sdk is initialized, it will only be called once\n        }\n    }\n    ```\n\n4. Processing jump results\n    ``` java\n    // U can get the result of a single jump\n    ARouter.getInstance().build(\"/test/1\").navigation(this, new NavigationCallback() {\n        @Override\n        public void onFound(Postcard postcard) {\n        ...\n        }\n\n        @Override\n        public void onLost(Postcard postcard) {\n        ...\n        }\n    });\n    ```\n\n5. Custom global demotion strategy\n    ``` java\n    // Implement the DegradeService interface\n    @Route(path = \"/xxx/xxx\")\n    public class DegradeServiceImpl implements DegradeService {\n        @Override\n        public void onLost(Context context, Postcard postcard) {\n            // do something.\n        }\n\n        @Override\n        public void init(Context context) {\n\n        }\n    }\n    ```\n\n6. Decoupled by dependency injection : Service management -- Exposure services\n    ``` java\n    // Declaration interface, other components get the service instance through the interface\n    public interface HelloService extends IProvider {\n        String sayHello(String name);\n    }\n\n    @Route(path = \"/yourservicegroupname/hello\", name = \"test service\")\n    public class HelloServiceImpl implements HelloService {\n\n        @Override\n        public String sayHello(String name) {\n            return \"hello, \" + name;\n        }\n\n        @Override\n        public void init(Context context) {\n\n        }\n    }\n    ```\n\n7. Decoupled by dependency injection : Service management -- Discovery service\n    ``` java\n    public class Test {\n        @Autowired\n        HelloService helloService;\n\n        @Autowired(name = \"/yourservicegroupname/hello\")\n        HelloService helloService2;\n\n        HelloService helloService3;\n\n        HelloService helloService4;\n\n        public Test() {\n            ARouter.getInstance().inject(this);\n        }\n\n        public void testService() {\n            // 1. Use Dependency Injection to discover services, annotate fields with annotations\n            helloService.sayHello(\"Vergil\");\n            helloService2.sayHello(\"Vergil\");\n\n            // 2. Discovering services using dependency lookup, the following two methods are byName and byType\n            helloService3 = ARouter.getInstance().navigation(HelloService.class);\n            helloService4 = (HelloService) ARouter.getInstance().build(\"/yourservicegroupname/hello\").navigation();\n            helloService3.sayHello(\"Vergil\");\n            helloService4.sayHello(\"Vergil\");\n        }\n    }\n    ```\n  \n8. Pretreatment Service\n    ``` java\n    @Route(path = \"/xxx/xxx\")\n    public class PretreatmentServiceImpl implements PretreatmentService {\n        @Override\n        public boolean onPretreatment(Context context, Postcard postcard) {\n            // Do something before the navigation, if you need to handle the navigation yourself, the method returns false\n        }\n\n        @Override\n        public void init(Context context) {\n    \n        }\n    }\n    ```\n\n9. Dynamic register route meta\nApplicable to apps with plug-in architectures or some scenarios where routing information\nneeds to be dynamically registered，Dynamic registration can be achieved through the\ninterface provided by ARouter, The target page and service need not be marked with @Route\nannotation，**Only the routing information of the same group can be registered in the same batch**\n    ``` java\n        ARouter.getInstance().addRouteGroup(new IRouteGroup() {\n            @Override\n            public void loadInto(Map\u003cString, RouteMeta\u003e atlas) {\n                atlas.put(\"/dynamic/activity\",      // path\n                    RouteMeta.build(\n                        RouteType.ACTIVITY,         // Route type\n                        TestDynamicActivity.class,  // Target class\n                        \"/dynamic/activity\",        // Path\n                        \"dynamic\",                  // Group\n                        0,                          // not need\n                        0                           // Extra tag, Used to mark page feature\n                    )\n                );\n            }\n        });\n    ```\n\n#### V. More features\n\n1. Other settings in initialization\n    ``` java\n    ARouter.openLog(); // Open log\n    ARouter.openDebug(); // When using InstantRun, you need to open this switch and turn it off after going online. Otherwise, there is a security risk.\n    ARouter.printStackTrace(); // Print thread stack when printing logs\n    ```\n\n2. API description\n    ``` java\n    // Build a standard route request\n    ARouter.getInstance().build(\"/home/main\").navigation();\n\n    // Build a standard route request, via URI\n    Uri uri;\n    ARouter.getInstance().build(uri).navigation();\n\n    // Build a standard route request, startActivityForResult\n    // The first parameter must be Activity and the second parameter is RequestCode\n    ARouter.getInstance().build(\"/home/main\", \"ap\").navigation(this, 5);\n\n    // Pass Bundle directly\n    Bundle params = new Bundle();\n    ARouter.getInstance()\n        .build(\"/home/main\")\n        .with(params)\n        .navigation();\n\n    // Set Flag\n    ARouter.getInstance()\n        .build(\"/home/main\")\n        .withFlags();\n        .navigation();\n\n    // For fragment\n    Fragment fragment = (Fragment) ARouter.getInstance().build(\"/test/fragment\").navigation();\n                        \n    // transfer the object \n    ARouter.getInstance()\n        .withObject(\"key\", new TestObj(\"Jack\", \"Rose\"))\n        .navigation();\n\n    // Think the interface is not enough, you can directly set parameter into Bundle\n    ARouter.getInstance()\n            .build(\"/home/main\")\n            .getExtra();\n\n    // Transition animation (regular mode)\n    ARouter.getInstance()\n        .build(\"/test/activity2\")\n        .withTransition(R.anim.slide_in_bottom, R.anim.slide_out_bottom)\n        .navigation(this);\n\n    // Transition animation (API16+)\n    ActivityOptionsCompat compat = ActivityOptionsCompat.\n        makeScaleUpAnimation(v, v.getWidth() / 2, v.getHeight() / 2, 0, 0);\n\n    // ps. makeSceneTransitionAnimation, When using shared elements, you need to pass in the current Activity in the navigation method\n\n    ARouter.getInstance()\n        .build(\"/test/activity2\")\n        .withOptionsCompat(compat)\n        .navigation();\n            \n    // Use green channel (skip all interceptors)\n    ARouter.getInstance().build(\"/home/main\").greenChannel().navigation();\n\n    // Use your own log tool to print logs\n    ARouter.setLogger();\n\n    // Use your custom thread pool\n    ARouter.setExecutor();\n    ```\n\n3. Get the original URI\n    ``` java\n    String uriStr = getIntent().getStringExtra(ARouter.RAW_URI);\n    ```\n\n4. Rewrite URL\n    ``` java\n    // Implement the PathReplaceService interface\n    @Route(path = \"/xxx/xxx\")\n    public class PathReplaceServiceImpl implements PathReplaceService {\n        /**\n        * For normal path.\n        *\n        * @param path raw path\n        */\n        String forString(String path) {\n            // Custom logic\n            return path;\n        }\n\n    /**\n        * For uri type.\n        *\n        * @param uri raw uri\n        */\n        Uri forUri(Uri uri) {\n            // Custom logic\n            return url;\n        }\n    }\n    ```\n\n5. Generate router doc\n    ``` gradle\n    // Edit build.gradle, add option 'AROUTER_GENERATE_DOC = enable'\n    // Doc file : build/generated/source/apt/(debug or release)/com/alibaba/android/arouter/docs/arouter-map-of-${moduleName}.json\n    android {\n        defaultConfig {\n            ...\n            javaCompileOptions {\n                annotationProcessorOptions {\n                    arguments = [AROUTER_MODULE_NAME: project.getName(), AROUTER_GENERATE_DOC: \"enable\"]\n                }\n            }\n        }\n    }\n    ```\n\n#### VI. Other\n\n1. Old version of gradle plugin configuration\n    ``` gradle\n    apply plugin: 'com.neenbedankt.android-apt'\n\n    buildscript {\n        repositories {\n            mavenCentral()\n        }\n\n        dependencies {\n            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'\n        }\n    }\n\n    apt {\n        arguments {\n            AROUTER_MODULE_NAME project.getName();\n        }\n    }\n\n    dependencies {\n        compile 'com.alibaba:arouter-api:x.x.x'\n        apt 'com.alibaba:arouter-compiler:x.x.x'\n        ...\n    }\n    ```\n\n2. Kotlin project configuration\n    ```\n    // You can refer to the wording in the \"module-kotlin\" module\n    apply plugin: 'kotlin-kapt'\n\n    kapt {\n        arguments {\n            arg(\"AROUTER_MODULE_NAME\", project.getName())\n        }\n    }\n\n    dependencies {\n        compile 'com.alibaba:arouter-api:x.x.x'\n        kapt 'com.alibaba:arouter-compiler:x.x.x'\n        ...\n    }\n    ```\n\n#### VII. Communication\n\n1. Communication\n\n    1. DingDing group1\n    \n        ![dingding](https://raw.githubusercontent.com/alibaba/ARouter/master/demo/dingding-group-1.png)\n\n    2. QQ group1\n    \n        ![qq](https://raw.githubusercontent.com/alibaba/ARouter/master/demo/qq-group-1.png)\n\n    3. QQ group2\n        \n        ![qq](https://raw.githubusercontent.com/alibaba/ARouter/master/demo/qq-group-2.png)\n","funding_links":[],"categories":["Technology","Android 应用","Projects List"],"sub_categories":["网络服务_其他"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba%2FARouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falibaba%2FARouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba%2FARouter/lists"}