39
GitHub - Tamicer/ComponentSample: Android运行时组件化方案
source link: https://github.com/Tamicer/ComponentSample?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
XModulable
组件化的套路通常是:
- 组件之间互不依赖、相互隔离
- app壳将组件注册到路由层
- 上层通过路由层查找组件,通过路组件暴露的服务实现通信交互
本例中的组件化:
- 路由采用ARouter实现
- XModulable SDK负责组件的注册和查找,这里的组件可视为组件服务的容器:
@XModule
——组件声明@InjectXModule
——组件注入声明XModulable
——作为组件的注册、查找和依赖注入
- 业务组件独立运行,只需要更改module.gradle对应的业务组件
isStandalone
为true即可
Latest Version
SDK | XModulable-api | XModulable-compiler | XModulable-annotation |
---|---|---|---|
最新版本 |
- 添加依赖配置
android {
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [ XModule : project.getName() ]
}
}
}
}
dependencies {
// gradle3.0以上建议使用implementation(或者api) 'com.xpleemoon.xmodulable:XModulable-api:x.x.x'
compile 'com.xpleemoon.xmodulable:XModulable-api:x.x.x'
annotationProcessor 'com.xpleemoon.xmodulable:XModulable-compiler:x.x.x'
...
}
@XModule(name = "XX组件名")
public class XXModule implements IModule{
}
- 初始化sdk
if (isDebug) {
XModulable.openDebug();
}
XModulable.init(this);
组件获取有两种方式:依赖注入和手动查询获取。
- 依赖注入:
```
public class TestActivity extends BaseActivity {
@InjectXModule(name = "xxx")
XXModule mXXModule;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
XModulable.inject(this);
}
}
```
- 手动获取:
```
XModulable.getInstance().getModule("XX组件名")
```
- 添加混淆规则
-keep class * implements com.xpleemoon.xmodulable.api.template.XModuleLoader
-keep class * implements com.xpleemoon.xmodulable.api.IModule
-keep class **$$XModulableInjector { *; }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK