luckybilly / CC

业界首个支持渐进式组件化改造的Android组件化开源框架,支持跨进程调用。Componentize your android project gradually.
https://luckybilly.github.io/CC-website/
Apache License 2.0
4.04k stars 636 forks source link

关于 Auto register Custom ActionProcessor into component 不生效 #3

Closed currer closed 6 years ago

currer commented 6 years ago

抱歉,大神再次打扰,学习使用您开源CC框架中,遇到一个问题: // compile project(':demo_component_b')后,自定义的ActionProcessor找不到,不能自动注册。 image compile project(':demo_component_b')后,就能注册成功了。 image 请问就是这样,还是我哪里操作不对呢。。 谢谢您百忙中抽出时间的解答。

luckybilly commented 6 years ago

@currer 上图中日志提示的是找不到ComponentB类进行自动注册。 是因为cc-settings-demo-b.gradle中配置了扫描IActionProcessor的实现类注册到ComponentB中,但gradle中没有依赖demo_component_b,导致找不到类。 日志起到一个提示作用,功能是正常的。

demo_component_b是为了演示以下内容:

  1. 组件作为app单独运行时如何跨app进行组件调用(用法跟在同一个app内完全一样
  2. 在少数比较复杂(需要处理的actionName比较多)的组件中为了避免IComponent实现类过于臃肿而采取的解耦措施,将具体的actionName交由对应的actionProcessor去处理。需要注意的是:IActionProcessor不是CC框架内部的接口,完全由开发者根据自己需求来自定义,若定义了这种接口需要在gradle中增加配置。,详情可参考 cc-settings-demo-b.gradle
  3. 在使用自定义的ActionProcessor时,可以在当前组件第一次被调用时再进行ActionProcessor的初始化(IComponent实现类是在CC第一次被调用时初始化的)
currer commented 6 years ago

@luckybilly 您好,感谢您的回答解惑,可是不依赖demo_component_b,日志除了不打印IActionProcessor相关的信息外,两个独立app,相互调用的时候,ComponentB是能够找到的。即功能是正常的。问题在于,返回值为-10,调试跟踪发现是进入到ComponentB的oncall回调方法的,但是是找不到IActionProcessor注册的子类的,即和日志反馈一样,未注册成功。

luckybilly commented 6 years ago

@currer demo_component_b作为app运行时,gradle中配置的AutoRegister参数有没有包含IActionProcessor的扫描(cc-settings-demo-b.gradle中有)

单独运行demo_component_b时,gradle console中应该会打印如下日志:

start auto-register transform...

register scan all class cost time: 188 ms

insert register code to file:/Users/billy/Documents/android/CC/demo_component_b/build/intermediates/transforms/auto-register/debug/1.jar
com/billy/cc/demo/component/b/ComponentB

codeInsertToClassName:com/billy/cc/core/component/ComponentManager.class
insert register code to file:/Users/billy/Documents/android/CC/demo_component_b/build/intermediates/transforms/auto-register/debug/13/com/billy/cc/demo/component/b/ComponentB.class
com/billy/cc/demo/component/b/processor/CheckAndLoginProcessor
com/billy/cc/demo/component/b/processor/GetDataProcessor
com/billy/cc/demo/component/b/processor/GetNetworkDataProcessor
com/billy/cc/demo/component/b/processor/LoginProcessor
com/billy/cc/demo/component/b/processor/ShowActivityProcessor

register insert code cost time: 63 ms
register cost time: 251 ms

PS:可以用JD-GUI工具查看一下class文件(文件路径在日志中已经输出了,如:/Users/billy/Documents/android/CC/demo_component_b/build/intermediates/transforms/auto-register/debug/13/com/billy/cc/demo/component/b/ComponentB.class)

luckybilly commented 6 years ago

@currer 先执行一下clean吧

currer commented 6 years ago

@luckybilly 您好,clean后,单独运行demo_component_b,打印结果如下所示,和您给的结果不同。并且继承IComponent是能够找到并注册成功的,而自定义的 [ 'scanInterface' : 'com.billy.cc.demo.component.b.processor.IActionProcessor' , 'codeInsertToClassName' : 'com.billy.cc.demo.component.b.ComponentB' , 'codeInsertToMethodName' : 'initProcessors' , 'registerMethodName' : 'add' ] 是找不到,注册不了。和gradle版本有关吗。测试环境:as3.0.1+gradle4.3 image

currer commented 6 years ago

补充:依赖demo_component_b后运行demo就可以注册和调用, image

luckybilly commented 6 years ago

@currer 在根目录的build.gradle中将AutoRegister的版本升级到1.1.1试试

currer commented 6 years ago

FAILURE: Build failed with an exception.

BUILD FAILED in 21s

luckybilly commented 6 years ago

@currer 这是个windows兼容的bug,我这边没有windows电脑,加个qq群帮我调试一下吧。 CC交流群:686844583

luckybilly commented 6 years ago

AutoRegister插件兼容windows的bug,版本升级到1.1.3已解决