luckybilly / CC

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

自动注册插件注册不上 #45

Closed JacksenLaw closed 6 years ago

JacksenLaw commented 6 years ago

interceptor:com.billy.cc.core.component.LocalCCInterceptor.CCResult:{"success":false,"code":1,"errorMessage":"has not support for action:login"}

componentName和actionName都是一样的

`public class ComponentB implements IComponent {

public static final String ComponentName = "library_b.ComponentB";

private AtomicBoolean initialized = new AtomicBoolean(false);
private final HashMap<String, IActionProcessor> map = new HashMap<>(4);

public void initProcessors() {
}

private void add(IActionProcessor processor) {
    map.put(processor.getActionName(), processor);
}

@Override
public String getName() {
    return ComponentName;
}

@Override
public boolean onCall(CC cc) {

// switch (cc.getActionName()) { // case "login": // map.put(cc.getActionName(), new LoginProcessor()); // break; // case "getNetData": // map.put(cc.getActionName(), new NetProcessor()); // break; // }

    if (initialized.compareAndSet(false, true)) {
        synchronized (map) {
            initProcessors();
        }
    }
    String actionName = cc.getActionName();
    IActionProcessor processor = map.get(actionName);
    if (processor != null) {
        return processor.onActionCall(cc);
    }
    CC.sendCCResult(cc.getCallId(), CCResult.error("has not support for action:" + cc.getActionName()));
    return false;
}`

其中map的size为0

luckybilly commented 6 years ago

如果需要像Demo_b那样使用ActionProcessor,需要注意以下两点:

  1. cc-settings-demo-b.gradle那样创建一个gradle文件,引用cc-settings.gradle并添加ActionProcessor自动注册的配置
  2. 在项目中的组件和主app module中都apply新创建的gradle文件替换cc-settings.gralde, 参考demo/build.gralde