Search Unity

Localization package - Fixing / automating the addressables issue when building for Andorid

Discussion in 'Localization Tools' started by Project-NSX, Mar 23, 2022.

  1. Project-NSX

    Project-NSX

    Joined:
    Apr 11, 2019
    Posts:
    25
    Hello

    I am aware of an issue with the localization package when building for Andoid.
    When new translations are added, the translations break. To fix this it is required to go to Window > Asset Management > Addressables > Groups. Inside the new window Build > Clean Build > All, and then New Build > Default Build Scripts.
    Performing these two actions then fixes the new translation when building for Android.

    I would like to ask if there's a fix for this issue, and if one is not present, then to ask if anyone is aware of a workaround to automate the rebuilding of the addressables when a build is run.

    I already have a build processor script that essentially ensures that VR is enabled for all scenes before starting to build (as this is a multiplayer project I have been using another static camera for testing, so VR isn't always enabled).
    From another post I can see that someone suggests running a couple of methods in the build processor script and this will rebuild the addressables database (or something to that effect). It was suggested to use the following two lines to do so:
    Code (CSharp):
    1.         AddressableAssetSettings.CleanPlayerContent();
    2.         AddressableAssetSettings.BuildPlayerContent();
    However, this creates build errors. If there is no fix for the addressables issue, is there a way to automate the "Clean build > all" and "New Build > Default Build Scripts" process so it doesn't need to be run every time a new translation is added?

    Thanks very much!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    This is not an issue, this is by design. Building Addressables creates asset bundles with all of the localization data contained, its a snapshot of that point. In the player the data is loaded from these asset bundles. If you make a change to the localization data then you need to rebuild these asset bundles. In the Editor you have 3 different types of Addressables play mode behaviours, the default just reads the assets directly, instead of using the asset bundles. If you want to match the player behavior then you can switch to `Use Existing Build`

    upload_2022-3-23_16-33-51.png

    This will now accurately reflect the localization data that the player will use.

    This should work. What version of Unity are you using and what are the error messages?
    It may be that you are doing the build too late or during the main player build. Can you run it before you run the player build?

    Also in Unity 2021.2+ there is an option to auto-build the addressables.
     
    Last edited: Mar 23, 2022
  3. Project-NSX

    Project-NSX

    Joined:
    Apr 11, 2019
    Posts:
    25
    Thanks very much for your reply. Ah I see.
    So if I understand you correctly switching the play mode scripts to "use existing build" will mean that I don't need to do "build > clean build > all" and "Build > new build > default build scripts" every time I add a new localisation to the table?
    Sorry if I'm not understanding it properly.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    No sorry, you will still need to do this. I meant if you wanted the Editor to use the same data so that you can tell if it's incorrect. You will always need to do a rebuild if you modify the localization data but this can be automated as you said.
     
  5. Project-NSX

    Project-NSX

    Joined:
    Apr 11, 2019
    Posts:
    25
    Ah I see, that's a great help thanks.
    For anyone who comes across this post, I found a script on here that asks if you want to build the addressables when you build.This script works by adding it to the Editor folder in Assets.
    Code (CSharp):
    1. /// <summary>
    2. /// The script gives you choice to whether to build addressable bundles when clicking the build button.
    3. /// For custom build script, call PreExport method yourself.
    4. /// For cloud build, put BuildAddressablesProcessor.PreExport as PreExport command.
    5. /// Discussion: https://forum.unity.com/threads/how-to-trigger-build-player-content-when-build-unity-project.689602/
    6. ///
    7. /// License: The MIT License https://opensource.org/licenses/MIT
    8. /// </summary>
    9. using UnityEditor;
    10. using UnityEditor.AddressableAssets;
    11. using UnityEditor.AddressableAssets.Settings;
    12. using UnityEngine;
    13. using System.Collections;
    14.  
    15. class BuildAddressablesProcessor
    16. {
    17.     /// <summary>
    18.     /// Run a clean build before export.
    19.     /// </summary>
    20.     static public void PreExport()
    21.     {
    22.         Debug.Log("BuildAddressablesProcessor.PreExport start");
    23.         AddressableAssetSettings.CleanPlayerContent(
    24.             AddressableAssetSettingsDefaultObject.Settings.ActivePlayerDataBuilder);
    25.         AddressableAssetSettings.BuildPlayerContent();
    26.         Debug.Log("BuildAddressablesProcessor.PreExport done");
    27.     }
    28.  
    29.     [InitializeOnLoadMethod]
    30.     private static void Initialize()
    31.     {
    32.         BuildPlayerWindow.RegisterBuildPlayerHandler(BuildPlayerHandler);
    33.     }
    34.  
    35.     private static void BuildPlayerHandler(BuildPlayerOptions options)
    36.     {
    37.         if (EditorUtility.DisplayDialog("Build with Addressables",
    38.             "Do you want to build a clean addressables before export?",
    39.             "Build with Addressables", "Skip"))
    40.         {
    41.             PreExport();
    42.         }
    43.         BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options);
    44.     }
    45.  
    46. }
     
    karl_jones likes this.