Version: 2019.4
Support for APK expansion files (OBB)
Un Solo Pase de Stereo Rendering para Android

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.

To patch your app:

  1. Update your script files.

    Note: If you change the layout of a script attached to a GameObject, 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 IL2CPP scripting backend (Otherwise move to the next step):

    1. Click the Player Settings button.
    2. In the Inspector, 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.

Por ejemplo:

    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 scripts 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

Support for APK expansion files (OBB)
Un Solo Pase de Stereo Rendering para Android
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961