Shadow icon indicating copy to clipboard operation
Shadow copied to clipboard

插件activity启动不了(通过debug调试发现转换的时候插件activity没有被替换)是什么原因?

Open wolrdprogrammer9823 opened this issue 4 years ago • 4 comments

异常日志: Process: com.wolfsea.shadowdevapp:smalltone, PID: 7408 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wolfsea.shadowdevapp/com.wolfsea.smalltone.SmallToneActivity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2079) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1737) at android.app.ContextImpl.startActivity(ContextImpl.java:1033) at android.app.ContextImpl.startActivity(ContextImpl.java:1004) at android.content.ContextWrapper.startActivity(ContextWrapper.java:414) at com.tencent.shadow.dynamic.loader.impl.DynamicPluginLoader$startActivityInPluginProcess$1.run(DynamicPluginLoader.kt:190) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:236) at android.app.ActivityThread.main(ActivityThread.java:8060) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

启动插件activity代码(shadow demo提供的) executorService.execute(() -> { try { InstalledPlugin installedPlugin = installPlugin(pluginZipPath, null, true); loadPlugin(installedPlugin.UUID, partKey); callApplicationOnCreate(partKey); Intent pluginIntent = new Intent(); pluginIntent.setClassName( context.getPackageName(), className ); if (extras != null) { pluginIntent.replaceExtras(extras); }

            Intent intent = mPluginLoader.convertActivityIntent(pluginIntent);
           //convertActivityIntent方法没有把插件activity替换为runtime中的PluginDefaultProxyActivity、 
             PluginSingleInstance1ProxyActivity、PluginSingleTask1ProxyActivity其中之一

            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mPluginLoader.startActivityInPluginProcess(intent);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (callback != null) {
            callback.onCloseLoadingView();
        }
    });

wolrdprogrammer9823 avatar Dec 21 '21 02:12 wolrdprogrammer9823

通过debug调试发现转换的时候插件activity没有被替换

预期和实际现象描述不清,看不懂。

异常日志说的也只是找不到Activity,如果写错了也没什么奇怪的。

如果描述不清楚问题,建议把代码push上来。https://github.com/Tencent/Shadow/blob/3d8a6d903c0c00ed934a98540af123b7d47e253f/CONTRIBUTING.md#issue

shifujun avatar Dec 21 '21 02:12 shifujun

这个应该不冲突的。 Intent intent = mPluginLoader.convertActivityIntent(pluginIntent); //convertActivityIntent方法没有把插件activity替换为runtime中的PluginDefaultProxyActivity、 PluginSingleInstance1ProxyActivity、PluginSingleTask1ProxyActivity其中之一,也就是代理activity. 没有把要跳转的插件activity替换成功,所以启动代理activity的实际上启动的是插件activity,插件activity没有在宿主中注册肯定找不到,所有log日志就提示activity没有到,没有在宿主中注册.现在的问题就时为什么没有替换成功?

wolrdprogrammer9823 avatar Dec 21 '21 05:12 wolrdprogrammer9823

你可以debug一下这两处代码: https://github.com/Tencent/Shadow/blob/7b02667258884fa15e9d40fcb951c63dc46fa051/projects/sdk/core/loader/src/main/kotlin/com/tencent/shadow/core/loader/managers/ComponentManager.kt#L162

https://github.com/Tencent/Shadow/blob/7b02667258884fa15e9d40fcb951c63dc46fa051/projects/sdk/core/loader/src/main/kotlin/com/tencent/shadow/core/loader/managers/ComponentManager.kt#L217

shifujun avatar Dec 21 '21 08:12 shifujun

我也遇到了同样偶现的问题,大佬现在解决了吗

gushiyong avatar Jan 07 '22 02:01 gushiyong