WMRouter: An Android Routing Framework for Componentized Development
WMRouter is an open‑source Android routing framework, originating from Meituan Waimai, that provides flexible URI dispatch and a ServiceLoader inspired by Java SPI, enabling component‑based navigation, dynamic registration, interceptors, singleton management, and decoupled communication for hybrid, multi‑module, and instrumented app architectures.
WMRouter is an Android routing framework designed with componentization in mind. It originated from Meituan Waimai to solve real‑world problems in the app’s evolution and has been open‑sourced for broader use.
Feature Overview
WMRouter provides two core modules: URI dispatch and ServiceLoader.
URI dispatch supports multiple schemes, hosts, paths, regex matching, dynamic Java registration or annotation‑based registration, global and local interceptors, extra/flags, custom animations, exported control, downgrade strategies, and listeners.
ServiceLoader, inspired by Java SPI, offers annotation auto‑configuration, retrieval of all implementations or a specific one by key, class or instance loading, singleton management, and method invocation.
Applicable Scenarios
Native + H5 hybrid development where pages need flexible routing and dynamic URI links.
Unified handling of external URI jumps (browser, WeChat, etc.) while preserving normal app startup flow.
Complex page‑jump logic such as login, location checks, or A/B testing.
Multi‑module/componentized projects requiring decoupled communication.
Strong business instrumentation needs (e.g., jump monitoring, error reporting).
Basic Concepts
Routing : The process of transmitting information from a source address to a destination address based on a protocol.
URI (Uniform Resource Identifier) is a string that identifies an internet resource. In Android, android.net.Uri handles scheme, host, path, and query parts.
Intent : Android’s mechanism for page navigation, supporting explicit (component name) and implicit (IntentFilter) jumps.
Code Examples
Explicit Intent:
Intent intent = new Intent(context, TestActivity.class);
intent.putExtra("param", "value");
startActivity(intent);Implicit Intent for opening a web page:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.meituan.com"));
startActivity(intent);Manifest configuration for a generic URI scheme:
<activity android:name=".app.UriProxyActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="demo_scheme" android:host="demo_host"/>
</intent-filter>
</activity>Sample UriHandler that processes HTTP links:
public class DemoUriHandler extends UriHandler {
public void handle(@NonNull final UriRequest request, @NonNull UriCallback callback) {
Uri uri = request.getUri();
if ("http".equalsIgnoreCase(uri.getScheme())) {
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
request.getContext().startActivity(intent);
callback.onComplete(UriResult.CODE_SUCCESS);
} catch (Exception e) {
callback.onComplete(UriResult.CODE_ERROR);
}
} else {
callback.onNext();
}
}
// ...
}Platformization & Reuse
As the Waimai app grew, the codebase was split into multiple modules, creating communication, reuse, dependency‑injection, and compilation challenges. WMRouter’s ServiceLoader module addresses these by allowing interface‑based loading of implementations, key‑based retrieval, and singleton management, thus decoupling modules and simplifying injection.
Annotation support reduces manual registration in the Application class, improving compile speed and reducing coupling.
Promotion & Summary
After solving internal problems, WMRouter was open‑sourced and promoted across Meituan’s ecosystem. Its design balances flexibility (customizable UriHandler, UriInterceptor) with ease of use (default implementations, Gradle plugin optimizations). It has become a core component in many Meituan Android apps.
References
Routing - Wikipedia
统一资源标志符 - 维基百科
Intent and Intent Filters
Introduction to the Service Provider Interfaces
Meituan Waimai Android Platform Evolution
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Meituan Technology Team
Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
