If the shader you're using isn't set to be local to the scene, the Viewport texture will work in the editor (for some reason? I can't tell why) but at runtime it'll try to find the viewport from the root of the tree, making the path wrong. If you set both the Viewport Texture and shader to be local to the scene, it'll work.
(ik this is three years old but im putting it here so the next person who needs to do this can find the answer on google instead of going round in circles being stuck for two hours like i did)