https://github.com/huolalatech/hll-wp-therouter-android
A framework for assisting in the renovation of Android componentization(帮助 App 进行组件化改造的动态路由框架)
https://github.com/huolalatech/hll-wp-therouter-android
android componentization dependency-injection kotlin modularization navigation router therouter
Last synced: 3 months ago
JSON representation
A framework for assisting in the renovation of Android componentization(帮助 App 进行组件化改造的动态路由框架)
- Host: GitHub
- URL: https://github.com/huolalatech/hll-wp-therouter-android
- Owner: HuolalaTech
- License: apache-2.0
- Created: 2022-08-29T10:36:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-09T03:32:06.000Z (11 months ago)
- Last Synced: 2025-05-09T03:38:45.100Z (11 months ago)
- Topics: android, componentization, dependency-injection, kotlin, modularization, navigation, router, therouter
- Language: Java
- Homepage: https://therouter.cn
- Size: 1.14 MB
- Stars: 1,209
- Watchers: 11
- Forks: 144
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
TheRouter: *Android componentization solution*
---
[](https://www.apache.org/licenses/LICENSE-2.0)
[](https://kotlinlang.org/)
[](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki)
Android | [Harmony](https://github.com/HuolalaTech/hll-wp-therouter-harmony) | [iOS](https://github.com/HuolalaTech/hll-wp-therouter-ios) | [中文官网](https://therouter.cn)
### A. Features
TheRouter core functions have four functionalities:
* Page Navigation([Navigator](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki/Navigator))
* Cross-module dependency injection([ServiceProvider](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki/ServiceProvider))
* Single module automatic initialization ([FlowTaskExecutor](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki/FlowTaskExecutor))
* Enable client apps to remotely load method dynamically ([ActionManager](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki/ActionManager))
* Demo:

### B. Introduction
**For more detailed documentation, please check the project wiki**:[Wiki](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki)
#### B1. Gradle configuration
|module| apt | router | plugin |
|---|----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
|version| [](https://repo1.maven.org/maven2/cn/therouter/apt/) | [](https://repo1.maven.org/maven2/cn/therouter/router/) | [](https://repo1.maven.org/maven2/cn/therouter/plugin/) |
```
// root build.gradle
classpath 'cn.therouter:plugin:1.3.0'
// app module
apply plugin: 'therouter'
// dependencies
kapt "cn.therouter:apt:1.3.0"
implementation "cn.therouter:router:1.3.0"
```
#### B2. initialization library
The library contains the automatic initialization function inside,link to: [Single module automatic initialization](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki/FlowTaskExecutor); therefore, there's no need for any initialization code. However, it is recommended that you set the `Debug` environment according to your business settings to view log information.
```
@Override
protected void attachBaseContext(Context base) {
TheRouter.setDebug(true or false);
super.attachBaseContext(base);
}
```
#### B3. page parameter injection
Called in the `onCreate()` method of `Activity` or `Fragment`:
(*It is recommended to do it directly in `BaseActivity(BaseFragment)`*)
```
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TheRouter.inject(this);
}
```
#### B4. page navigation
For the meaning of the annotation `@Route`, please check the documentation: [Page Navigation](https://github.com/HuolalaTech/hll-wp-therouter-android/wiki/Navigator)
```
@Route(path = "http://therouter.com/home", action = "action://scheme.com",
description = "second page", params = {"hello", "world"})
public class HomeActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TheRouter.build("Path")
.withInt("intValue", 12345678)
.withString("str_123_Value", "传中文字符串")
.withBoolean("boolValue", true)
.withLong("longValue", 123456789012345L)
.withChar("charValue", 'c')
.withDouble("double", 3.14159265358972)
.withFloat("floatValue", 3.14159265358972F)
.navigation();
}
}
```
### C. proguard rules configuration
```
# need add for Fragment page route
# -keep public class * extends android.app.Fragment
# -keep public class * extends androidx.fragment.app.Fragment
# -keep public class * extends android.support.v4.app.Fragment
-keep class androidx.annotation.Keep
-keep @androidx.annotation.Keep class * {*;}
-keepclassmembers class * {
@androidx.annotation.Keep *;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep ;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep ;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep (...);
}
-keepclasseswithmembers class * {
@com.therouter.router.Autowired ;
}
```
### D. Build and Debug
#### D1. project module description
```
TheRouter
├─app
│ └──sample
├─business-a
│ └──modular business demo
├─business-b
│ └──modular business demo
├─business-base
│ └──modular business demo
│
├─apt
│ └──Annotation processor tool code
│
├─plugin
│ └──Gradle plugin
│
└─router
└──library code
```
#### D2. run Project
1. Open `local.properties` and declare the modules you want to debug. For example, if you want the source code to debug the `apt` module, you can declare `apt=true`
2. sync Gradle change
#### D3. plugin source code debugging
`plugin` debugging is special; you'll need to modify the `module` name to enable plugin debugging.
1. Modify the `plugin` folder name to `buildSrc` (Case sensitive)
2. Remove `classpath` reference in root `build.gradle`
3. sync Gradle change
### E. Change Log
link to Releases:[Github Releases](https://github.com/HuolalaTech/hll-wp-therouter-android/releases)
### F. Author

### G. LICENSE
TheRouter is licensed under the Apache License 2.0: [LICENSE](https://github.com/HuolalaTech/hll-wp-therouter-android/blob/main/LICENSE).