4

I am using an Android Unity plugin for a library which followed the prior Unity 5 suggested structure and it was working perfectly. The package was placing the necessary files under Assets/Plugins/Android where the jar file existed and in folder Assets/Plugins/Android/res/raw some .js and .css files used by the library. Everything was working perfectly but when upgraded to Unity 5 hundreds of errors appeared regarding the .js and .css files. (like insert semicolon at a specific line, or expected token at that line etc.)

I am aware of the changes in Unity 5, especially as mentioned here: http://docs.unity3d.com/Manual/PluginInspector.html , however I cannot find a proper solution to resolve this. So what i think the issue is that Unity is trying to parse these files as something different most probably as c# files resulting to the errors. How can exclude files in Assets/Plugins/Android/res/raw from that procedure, or at least how can i handle this situation. Do i have to restructure the file hierarchy with the new Unity 5? As far as I read they can keep the same structure for backwards compatibility.

Steven
  • 166,672
  • 24
  • 332
  • 435
andreasv
  • 689
  • 3
  • 11
  • 26
  • i am not farmiliar with unity, but I had similar issues with webview... I fixed the issue by moving files from /raw/ to /assets/ ... can you try the same? – Bojan Kseneman Apr 14 '15 at 20:24
  • thank you Bojan, however this means I will have to change the library too since it is looking in the /raw folder. Is assets folder not being parsed by the compiler in Unity 5? – andreasv Apr 15 '15 at 04:36
  • Yes, you need to try and parse from assets – Bojan Kseneman Apr 15 '15 at 05:38
  • Hey Bojan this does not work for 2 reasons. It seems that Unity still parse the assets folder, so issue remains. And secondly i am looking for a solution without changing the third party sdk library – andreasv Apr 15 '15 at 07:29

1 Answers1

0

We've got a similar issue on one of our projects, and there seems to be no way of preventing unity (at least, to try) to compile all your scripts. At this point unity expects the .js files to be "unity script files" and tries to compile them, which of then fails, when the .js files are some kind of web stuff.

I must admit, that I have no clue, why unity changed the behaviour from 4.x to 5, as the folder was indeed skipped from compilation in unity prior to version 5. See also "specific folders" section below.

Possible solutions

1. Putting the potential script files in a specific folder

There are some specific folders, where unity does not try to compile your files e.g. WebPlayerTemplates.

see http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html

2. Renaming the potential script files

As the unity compilation will only be performed for certain files (e.g. .cs or .js) you can avoid compilation by renaming them to e.g. .js_


For sure, both solutions will break your plugin in the first place, if you won't adapt it accordingly.

But what you can do is, to use a pre build hook to revert your changes (renaming or moving the files back) and make the plugin work on the device. And just after the build again, to avoid the compilation (errors).


How to achieve this

Just create a custom build script (must be stored in an Editor folder, e.g. Assets/Editor). You'll find a new menu in unity named Build with an entry CustomBuild, where you can (and must) start your build.

Minimum version:

using UnityEditor;
using UnityEngine;

public class BuildProcessor {

    [MenuItem ("Build/Custom Build", false, 0)]
    static void CustomBuild() {
        PreProcess();
        BuildPipeline.BuildPlayer(new string[] { "your-main-scene.unity" }, "build-output-dir", BuildTarget.Android, BuildOptions.None);
        PostProcess(); 
    }

    static void PreProcess() {
        //Your pre-process here (e.g. rename all files from .js_ to .js)
    }

    static void PostProcess() {
        //Your post-process here (e.g. rename all files back from .js to .js_)
    }
}

I hope this will somehow satisfy your needs, let me know if something is not clear to you.

Community
  • 1
  • 1
d4Rk
  • 6,622
  • 5
  • 46
  • 60
  • Hey d4Rk thank you for your answer. However this does not solve the problem since i do not want to force anyone to custom build in order to avoid the issue with the js files. From what I understand now Unity 5 suggests the creation of Android plugins with the use of .aar files instead of the classic Plugins/Android/res/raw folders. With .aar library projects the resources are packed and not visible to the parsers from what i understand. I am still though trying to find a more solid solution – andreasv Apr 20 '15 at 15:27