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.
Important: App patching is not supported for Chrome OS based devices.
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
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.