Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

BuildPipeline BuildPlayer failing in 5.4.1 Android

Discussion in 'Formats & External Tools' started by Deleted User, Nov 1, 2016.

  1. Deleted User

    Deleted User

    Guest

    I'm in the process of getting our project build working on our TeamCity build agents.
    I've created a C# class with a static method (BuildAndroid) to set up all the parameters for the build and then call BuildPipeline.BuildPlayer.
    It's an Android project, I have installed the SDK, NDK and JDK and set up the paths to these from the method.
    The BuildAndroid method is hooked up to an editor menu to allow local testing within the editor and on TeamCity it is called via a batch file using the -executeMethod command line option.
    I've set up a simple test project and this all works fine, both within the editor and on TeamCity.

    The problem I have is that if _any_ warning is generated during the build, then the build will abort without error.
    This is a problem as I'm actually trying to get a much larger project up and running on the build agent and as it stands the project generates a lot of warnings ( >300 ).
    The odd thing is that the build only aborts when the build is executed from the command line via my batch file ( both local PC & TeamCity).
    Running the exact same build method from within the editor always succeeds with the creation of the apk as expected.

    Initially I thought that this was because the build was running in strict mode from the command line, however I found no documented way of disabling this.
    To counter what I thought was strict compilation I added -warn:0 to both gmcs.rsp & smcs.rsp.
    This got rid of most of the errors and from the logs created I can see that now the command line build does get a lot further.

    There are however more warnings that cause the build to abort and they're all outside the scope of C# ( so any thoughts of strict mode can be discounted).
    Some warnings reported missing scripts attached to game objects (which are now fixed), such as .
    "Script attached to 'CompositionRoot' in scene 'Assets/Scenes/SceneOne.unity' is missing or no valid script is attached.".
    Other warnings advise on performance issues such as this
    "Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices."

    Comparing the log from the command line build and Editor.log from the editor build, the command line build fails at the point at which the warning would be reported.
    In editor.log the warning appears, in the command line log it doesn't.

    All of this makes me think that there may be something going awry with the way that warnings are reported, almost as if it's trying to print to a null device or similar.
    ( Running the command line and redirecting stout & stderr to log files doesn't work either btw )

    Any suggestions on what may be going wrong?
    Is there a stub class for error reporting I need to create or similar?
     
  2. Simon-O

    Simon-O

    Joined:
    Jan 22, 2014
    Posts:
    51
    I've not had to do this myself and this is nothing but a wild-ass guess but...

    I'd imagine that the build process outputs warnings to STDERR not STDOUT and IO pipes are handled differently between a GUI, command line and build process, so seems like a good candidate.

    I've worked with build systems in the past that treat _any_ STDERR output as a failure (and also with processes that abort if they attempt to write to STDERR and get a broken pipe).

    To further diagnose your problem, I'd suggest creating a tiny one-liner that writes something to STDERR and then call that instead of your build. See if you're getting the same result.

    You might also try changing the line in your build process that calls your build script to forcibly redirect STDERR to /dev/nul or similar for testing purposes.

    If neither of the above work, let's try decoupling the process further until we can narrow down what exactly causes it to break.

    We can try having the build process run a wrapper script which in turn launches the real build. If this still works from a command line and not from the build process, then we need to start looking at environment variables, and other differences in the way the process is launched.
     
    Last edited: Jan 9, 2017
  3. Deleted User

    Deleted User

    Guest

    Yes, I thought it would be something along these lines too.
    Initially I had a very simple project ( ball on a plane ) and a 10 line script to test.
    Even with a simple "variable not used" type of warning it would crash with no error.

    However, I have a feeling that this may have been due to one of the plugins we have or an environmental change due to an upgrade.

    What happened in the end is that I removed all warnings ( both compiler and general Unity warnings ) and at this point the project built ok from the command line on a TeamCity build agent.

    We then just made doubly sure we had no warnings, ever :)
    We also fixed a few other issues relating to the Android keystore, upgraded a few plugins, installed windows updates etc..

    Sometime later a warning crept back in, as they always do!
    However, this time the log showed the warning rather than crashing with no error.
    Unity had exited cleanly, and produced a good Android build as the warning was minor.

    I don't know what actually fixed the problem in the end.
    It could have been any number of different changes that happened after we had our zero warnings policy in place.