Search Unity

PostProcessBuild, PreProcessBuild

Discussion in 'Unity Build Automation' started by any_user, Jan 26, 2015.

  1. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    I'm having issues with my [PostProcessBuild] function, which works without problems locally:

    Code (CSharp):
    1.  
    2.     [PostProcessBuild]
    3.     public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    4.     {
    5.         BuildBundlesForCurrentPlatform ();
    6.  
    7.         string srcFolder = GetAssetBundleDir (target);
    8.  
    9.         if (!Directory.Exists (srcFolder))
    10.         {
    11.             Debug.LogError("PostProcessBuild: Folder doesn't exist: "+srcFolder);
    12.             return;
    13.         }
    14.  
    15.         string targetFolder = GetStreamingAssetsPathInBuild(target,pathToBuiltProject) +"AssetBundles/";
    16.         EditorFileUtils.EnsureFolders (targetFolder);
    17.  
    18.         Debug.LogFormat( "Copy asset bundles from '{0}' to: {1}",srcFolder,targetFolder);
    19.  
    20.         EditorFileUtils.CopyDirectory (srcFolder, targetFolder);
    21.     }
    22.  
    23.     static string GetStreamingAssetsPathInBuild(BuildTarget target, string pathToBuiltProject)
    24.     {
    25.         if (target.ToString ().Contains ("OSX"))
    26.         {
    27.             return pathToBuiltProject+"/Contents/Resources/Data/StreamingAssets/";
    28.         }
    29.         if (target.ToString ().Contains ("Windows"))
    30.         {
    31.             string name = pathToBuiltProject.Substring( pathToBuiltProject.LastIndexOf('/')+1).Replace(".exe","") ;
    32.             return pathToBuiltProject+"/"+name+"_Data/StreamingAssets/";
    33.         }
    34.         if (target== BuildTarget.iOS)
    35.         {
    36.             return pathToBuiltProject+"/Data/Raw/";
    37.         }
    38.         if (target== BuildTarget.WebGL )
    39.         {
    40.             return pathToBuiltProject+"/StreamingAssets/";
    41.         }
    42.        
    43.         if ( target == BuildTarget.WebPlayer)
    44.         {
    45.             return pathToBuiltProject+"/Raw/";
    46.         }
    47.  
    48.         throw new UnityException("Platform not implemented");
    49.     }
    This function rebuilds asset bundles and copies them to the streaming assets folder in the build (eg. a folder called "Raw" next to the build in case of the web player).

    BuildBundlesForCurrentPlatform builds asset bundles. In case of webplayer build they are saved in "AssetBundles/webplayer" in the project folder. Everything is written in the log and works so far. Then it will be copied to the target folder in the build, but this doesn't seem to work, or at least the bundles are not accessible from the built web player.

    Might be a permission issue, but the confusing thing is, that after the successful asset bundle build logs I find no more log output written from this function, neither the "Folder doesn't exist..." message nor the "Copy asset bundles..." and there is also no error message.

    I can't really figure out how to debug it when I have no log messages. What could that be?


    Another issue: I know it's maybe not the right place to ask, but is there a way to get a PreProcessBuild attribute in (non-cloud-build)-unity? It would be very useful for many cases. In my case it would help me building these asset bundles to the streaming assets folder before build. (I'm using asset bundles, since in Unity 5 we can't use Resources.LoadAsync anymore and we are forced to use asset bundles for async loading.) Currently I'm using PostProcessBuild to copy the asset bundles to the right place AFTER build, but this doesn't work for android, because it's not possible to copy anything into the apk after build easily, so a Pre-build callback would be very nice.
     
    yaegz likes this.
  2. hypeNate

    hypeNate

    Unity Technologies

    Joined:
    Apr 4, 2014
    Posts:
    272
    @any_user - very interesting, it's hard to say at first glance what could be going on here. I think the quickest way for us to resolve this problem would be for you to file a support ticket. Thanks!
     
  3. hypeNate

    hypeNate

    Unity Technologies

    Joined:
    Apr 4, 2014
    Posts:
    272
  4. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    To update all:

    The issue here was/is that the StreamingAssets folder which is generated for WebBuilds is currently not uploaded to your Unity Cloud Build so you can not load them locally. But you still can stream them from the web.
     
  5. pws-devs

    pws-devs

    Joined:
    Feb 2, 2015
    Posts:
    63
    I'm having some weird issues with the postprocess build in my project. On my local machines, the processes run fine. On UCB for Android, it works fine too. Only on UCB for iOS, the post-process does not seem to run or complete at all before running xcode. I've tested the same process on a local mac machine and it runs fine.
    For testing purposes, I've even added some debug logs into the post process to check on the UCB logs. On Android builds, the log output is there. But on the iOS builds, the stack call log is there but not the log output.

    I think I've pinpointed my issue down to getting the pathToBuiltProject parameter on the OnPostProcessBuild. The path returned cannot be read as a string.
     
    Last edited: Mar 2, 2015
    yaegz likes this.
  6. MatmiDeveloper

    MatmiDeveloper

    Joined:
    Sep 27, 2013
    Posts:
    10
    Any luck with this?

    I seem to be having the same issue. See post - http://forum.unity3d.com/threads/framework-not-added-to-xcode-project.432581/
     
    yaegz likes this.
  7. yaegz

    yaegz

    Joined:
    Sep 23, 2016
    Posts:
    10
    Having very similar issue. My local iOS builds work great but when building through UCB I am experiencing some very different results with lighting and things not showing up. This is for the same Scene and Build mind you. Here's some screenshots taken from today (September 26, 2016)

    Screen Shot 2016-09-26 at 10.21.17 PM.png


    Screen Shot 2016-09-26 at 10.15.04 PM.png
     
  8. Mouldi

    Mouldi

    Joined:
    Feb 23, 2013
    Posts:
    20
    @yaegz how's that a similar issue!!!
     
  9. tarmo-jussila

    tarmo-jussila

    Joined:
    Jun 4, 2015
    Posts:
    42
    This is still an issue for me in 2020. Any luck with this? My issue is with PostProcess script when building iOS on the Unity Cloud - it doesn't run. Locally built iOS runs the PostProcess script just fine.
     
  10. minidisc

    minidisc

    Joined:
    Aug 16, 2012
    Posts:
    10
    Still an issue in 2021.

    I have two projects using the same post process scripts but the scripts only work in one of those projects when building for iOS on Cloud Build. The scripts are totally ignored in the other project. Building locally on Mac works as expected, only Cloud Build ignores the scripts.

    The post process scripts are PListProcessor and GA_PostprocessBuild from AdMob and GameAnalytics, respectivelly. I've tried changing the use of PostProcessBuild attribute in those scripts to implementing the IPostprocessBuildWithReport interface but the result is the same, the methods are not called by Cloud Build. My own scripts implementing IPostprocessBuildWithReport works fine though. I'm using Unity 2020.3.11f1 for both projects on Cloud Build.

    Has anyone with this issue found a solution?
     
    Last edited: Aug 26, 2021
  11. rajivrao

    rajivrao

    Unity Technologies

    Joined:
    Feb 19, 2019
    Posts:
    111
    Hey @minidisc sorry for the delay reaching out. If this is still an issue, would suggest submitting a support ticket if you haven't already. It'll be easier to check out your project to help see what's not working and prioritize a bug if that's the case.
     
  12. FrankdenUijlBaselinez

    FrankdenUijlBaselinez

    Joined:
    Nov 1, 2021
    Posts:
    5
    I have the same issue right now. I have submitted a ticket #1140668
     
    rajivrao likes this.