Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Streamin Assets files optional compression for Android

Discussion in 'Android' started by afedulov, Sep 27, 2023.

  1. afedulov

    afedulov

    Joined:
    Aug 6, 2019
    Posts:
    4
    Hellow. My question is how to setup
    Code (CSharp):
    1. aaptOptions {
    2.         noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
    3.     }
    4.  
    in mainTemplate.gradle file in such a way that some folders within StreamingAssets are compressed and others aren't.

    Why: we have a lot of files in StreamingAssets which leads to a known problem when apk build fails due to too many files in StreamingAssets folder. Which is actually noCompress variable containing paths of all non-compressed files and for some reason too big length of this string leads to apk build failure.
    We've fixed it by simply set unityStreamingAssets variable to an empty string in gradleTemplate.properties file which enables compression for all files in StreamingAssets. Now all of our assets are compressed, build size is slightly smaller, and loading time is slightly longer. But that is true only for smaller assetbundles, for the case of assetbundle of a size like 80mb loading time is tremendous, and 1kb texture is loaded for 1 second from such assetbundle.

    That why we need a way to keep most of our build-in assets as compressed and keep several big files as non-compressed. As I understand noCompress variable is what I need to define pattern for folders or/and files that is supposed to be excluded from compression.
    Let's assume we have all big assetbundles in the Assets/StreamingAssets/NoCompressDir, and all files have bigbundle_ prefix.
    I've tried something like this but with no result.
    Code (unityStreamingAssets = '' //at this point all files from StreamingAssets would be compressed CSharp):
    1. aaptOptions {
    2.         noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ') + ['NoCompressDir']
    3. //or
    4.         noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', '), 'NoCompressDir'
    5. //or
    6.         noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ') +['bigbundle_']
    7. //or
    8.                noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ') +['bigbundle_.']
    9.     }
    10.  
    So I simply missing the right syntax to define it. And the most appropriate way would be to exclude the whole folder, instead of relying on some prefix or extension.
     
  2. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,817
    As per the documentation, it accepts extensions and not prefixes. So, try giving bigbundle as extension to those files instead of prefix.


    I suppose noCompress can only operate at file level only but not at directories (Any one -> Pls correct me if i'm wrong.)

    Not sure if this is a possible solution but will this work for your case?
    1. Give an extension to the files you don't want to compress (in your case all the larger size files)
    2. In custom gradle.properties, append the extension to unityStreamingAssets entry.
    Let me know how it goes.


    Cheers,
    VB Team
     
    Last edited: Sep 27, 2023