Version: 2021.1
Play Asset Delivery
Android symbols

App patching for fast development iteration

Depending on the Project size, building an app for Android can take a significant amount of time. To perform faster iterations during development, you can choose to patch the app package instead of rebuilding it. When you patch a build, only script-related files are sent to the device.

Build settings window for Android.
Build settings window for Android.

Patching your app

Before you can patch an app, you must have built and installed it on the device. For more information, see Building apps for Android.

Important: App patching is not supported for Chrome OS based devices.

To patch your app:

  1. Update your script files.

    Note: If you change the layout of a script attached to a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
    See in Glossary
    , such adding new public variables, the Script Only Build and patching process will fail.

  2. In the Editor, click File > Build Settings.

  3. From the Build Type drop-down menu, select Development.

  4. If you are using the IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
    See in Glossary
    scripting backendA framework that powers scripting in Unity. Unity supports three different scripting backends depending on target platform: Mono, .NET and IL2CPP. Universal Windows Platform, however, supports only two: .NET and IL2CPP. More info
    See in Glossary
    (Otherwise move to the next step):

    1. Click the Player SettingsSettings that let you set various player-specific options for the final game built by Unity. More info
      See in Glossary
      button.
    2. In the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
      See in Glossary
      , expand the Other Settings section.
    3. If Strip Engine Code is checked, uncheck it.
  5. Check the Scripts Only Build checkbox.

  6. Click Patch or Patch & Run.

After building the updated script files, Unity sends updated files to the device specified in the Run Device field.

If you have implemented your own build pipeline, you can use the scripting API to patch your app by passing the BuildOptions.BuildScriptsOnly and BuildOptions.PatchPackage options to the BuildPipeline.BuildPlayer method.

For example:

    BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
    buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity"};
    buildPlayerOptions.target = BuildTarget.Android;

    // Build & Run the game normally, this will install the application on the android device
    buildPlayerOptions.options = BuildOptions.AutoRunPlayer
    BuildPipeline.BuildPlayer(buildPlayerOptions);

    // Modify some scripts in your Unity Project
    // Patch & Run the application
    // (Unity will only recompile script files and push only the necessary files to the android device)
    buildPlayerOptions.options = BuildOptions.BuildScriptsOnly | BuildOptions.PatchPackage | BuildOptions.AutoRunPlayer;
    BuildPipeline.BuildPlayer(buildPlayerOptions);

How does app patching work?

Unity sends the files containing the updated scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary
the app’s cache folder. When the app starts, the app checks the cache folder before loading files. If the app finds a required file, the file from cache folder is loaded instead of the app’s data folder.

The files that Unity sends depend on which scripting backend you are using:

Mono

Managed assemblies compiled from Project script files, packages script files or asmdef files are sent to /storage/emulated/0/Android/data/<PackageName>/cache/ScriptOnly/<UnityVersion>/mono/Managed

IL2CPP

  • libil2cpp.so is sent to /data/data/<PackageName>/cache/ScriptOnly/<UnityVersion>/il2cpp

    Note: This is an internal cache. Due to security enhancements introduced in Android 7.0, it’s not possible to load a dynamic library from emulated storage. For additional information, see Android 7.0 Behavior Changes on the Android developer website.

  • IL2CPP resource files are sent to /storage/emulated/0/Android/data/<PackageName>/cache/ScriptOnly/<UnityVersion>/il2cpp

Clearing patch files

You can use the Android storage settings to clear the app’s cache which removes the patch files installed by the Script Only build process. To clear the cache on the device, go to settings and open your application list. Typically there is an option to clear stored data and/or the cache. In some implementations of the Android OS, you might need to drill down into a storage option to find the option to clear the cache.


2018–11–13 Page published

Play Asset Delivery
Android symbols