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.
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:
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.
In the Editor, click File > Build Settings.
From the Build Type drop-down menu, select Development.
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):
Check the Scripts Only Build checkbox.
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);
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:
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
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
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 with editorial review
Did you find this page useful? Please give it a rating: