Shadow icon indicating copy to clipboard operation
Shadow copied to clipboard

使用maven源码实现多插件启动的问题

Open pangliang071 opened this issue 3 years ago • 11 comments

我用sample下maven作为我的开发源码, 一、将plugin-project复制了一份,作为另外一个插件,然后将里面的partKey 改为 'sample-plugin2'。将包名改为“com.tencent.shadow.sample.plugin2”。打包成zip后再重命名为"plugin2-debug.zip" 二、将manager-project 里面的 samplePluginManager.java中enter函数中复制了一个代码如下:

public void enter(final Context context, long fromId, Bundle bundle, final EnterCallback callback) { if (fromId == Constant.FROM_ID_START_ACTIVITY) { bundle.putString(Constant.KEY_PLUGIN_ZIP_PATH, "/data/local/tmp/plugin-debug.zip"); bundle.putString(Constant.KEY_PLUGIN_PART_KEY, "sample-plugin"); bundle.putString(Constant.KEY_ACTIVITY_CLASSNAME, "com.tencent.shadow.sample.plugin.MainActivity"); onStartActivity(context, bundle, callback); }else if (fromId == Constant.FROM_ID_START_ACTIVITY2) { bundle.putString(Constant.KEY_PLUGIN_ZIP_PATH, "/data/local/tmp/plugin2-debug.zip"); bundle.putString(Constant.KEY_PLUGIN_PART_KEY, "sample-plugin2"); bundle.putString(Constant.KEY_ACTIVITY_CLASSNAME, "com.tencent.shadow.sample.plugin2.MainActivity"); onStartActivity(context, bundle, callback); }else if (fromId == Constant.FROM_ID_CALL_SERVICE) { callPluginService(context); } else { throw new IllegalArgumentException("不认识的fromId==" + fromId); } } 三、将宿主增加了一个按钮2,用于启动插件2.代码如下

Button button2 = new Button(this); button2.setText("启动插件2"); button2.setOnClickListener(new View.OnClickListener() { @OverRide public void onClick(final View v) { v.setEnabled(false);//防止点击重入 PluginManager pluginManager = InitApplication.getPluginManager(); pluginManager.enter(SecondActivity.this, FROM_ID_START_ACTIVITY2, new Bundle(), new EnterCallback() { @Override public void onShowLoadingView(View view) { SecondActivity.this.setContentView(view);//显示Manager传来的Loading页面 }

            @Override
            public void onCloseLoadingView() {
                SecondActivity.this.setContentView(linearLayout);
            }

            @Override
            public void onEnterComplete() {
                v.setEnabled(true);
            }
        });
    }
});

linearLayout.addView(button2);
//==================================

四、将plugin-debug.zip,plugin2-debug.zip,sample-manager-debug.apk上传到 data/local/tmp下面。 五、运行sample-host ,现象是点击启动插件1按钮,插件1能起来,再点启动插件2按钮,程序崩溃。 重新安装sample-host,先点击启动插件2按钮,插件2可以起来,再点启动插件1按钮,程序崩溃。 六、错误信息如下:java.lang.RuntimeException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tencent.shadow.sample.host/com.tencent.shadow.sample.plugin2.MainActivity}; have you declared this activity in your AndroidManifest.xml? at com.tencent.shadow.sample.manager.SamplePluginManager$1.run(SamplePluginManager.java:102) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919) Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tencent.shadow.sample.host/com.tencent.shadow.sample.plugin2.MainActivity}; have you declared this activity in your AndroidManifest.xml? 七、我想知道哪里出现了问题,宿主,manager,插件1,还是插件2,我这么做的过程有没有问题呢?

pangliang071 avatar Dec 07 '21 04:12 pangliang071

@shifujun 帮帮我,现在项目进行不下去了。已经卡在这一周没有进展了。

pangliang071 avatar Dec 07 '21 05:12 pangliang071

已经卡在这一周没有进展了。

你可能需要更加仔细阅读说明和代码。maven那个工程只是为了演示如何正常接入SDK的。调试Shadow最好还是用source工程。那里面已经有多插件的演示了。

看起来只是一个ActivityNotFoundException,那么要么是真的没有注册在Manifest里,要么是没有loadPlugin。只要你debug过sample的插件启动流程,应该很容易发现问题。如果说只是把插件1复制成插件2,你完全可以简单的全文搜索原先的名字,很容易就能搞清楚原本的参数都设置在哪。

作为一个开源项目,而不是付费服务,我们只能尽量通过代码分享所有信息。不过#245 中也有一些人贡献了图和文档,你可以尝试从它们理解SDK。

另外,你应该把你的代码push上来,而不是靠文字描述,这样别人没法测试它,也看不到实际的代码改动。

shifujun avatar Dec 07 '21 07:12 shifujun

@shifujun 我将代码传上来了,只改了maven下面的代码。还是想用maven里面的代码,因为宿主、manager、插件都是分离的,用起来特别顺手,但是还是被多插件这块难住了。希望能通过简单的修改可以实现多插件的功能。谢谢啦。 https://github.com/pangliang071/shadow

pangliang071 avatar Dec 07 '21 08:12 pangliang071

我收到你的邮件啦,我会尽快回复的哦,谢谢

Only efforts can prove that I existed in this world  ---jarlen

jarlen avatar Dec 07 '21 08:12 jarlen

@shifujun 我将代码传上来了,只改了maven下面的代码。还是想用maven里面的代码,因为宿主、manager、插件都是分离的,用起来特别顺手,但是还是被多插件这块难住了。希望能通过简单的修改可以实现多插件的功能。谢谢啦。 https://github.com/pangliang071/shadow

你的代码看起来离能正常工作非常远,建议你还是参考 08da57dd53ae76a002a1fa341b170fd469151e68 吧。

shifujun avatar Dec 07 '21 09:12 shifujun

不是非常远,我这只差一步,就是将uuid.txt放到build里面重新打包后,就可完美运行。

pangliang071 avatar Dec 11 '21 05:12 pangliang071

不是非常远,我这只差一步,就是将uuid.txt放到build里面重新打包后,就可完美运行。

我也是和你完全一样的操作方式和报错情况。这样不就有重复的runtime和loader了?

scaupdc avatar Dec 23 '21 02:12 scaupdc

@pangliang071 按照你这种方式实现多插件的话,最后怎么解决的?

marufei avatar Jan 13 '22 01:01 marufei

是不是SamplePluginManager只有一个的原因呢?

donway avatar Feb 16 '22 10:02 donway

不是很远,我只是差一点,一步就是将uuid.txt编译好之后,就可以完美运行了。

只需要在 build.gradle 中增加 uuid = '1234567890' 即可

oksimple avatar May 07 '22 08:05 oksimple

@pangliang071 我也有多插件多进程的需求,请问你正常接入了吗?有没有demo提供下

chenlin139 avatar Jul 12 '22 07:07 chenlin139