プロジェクトのサイズによっては、Android のアプリケーションのビルドにかなりの時間がかかる場合があります。開発中により高速なイテレーションを実行するために、アプリケーションパッケージを再ビルドする代わりにパッチすることを選択できます。 ビルドにパッチ処理を行う場合、 スクリプト関連のファイルのみがデバイスに送信されます。
アプリケーションにパッチを行う前に、アプリケーションをビルドしてデバイスにインストールしておく必要があります。詳細は、Android アプリケーションのビルド を参照してください。
重要: アプリケーションのパッチ適用は、Chrome OS ベースのデバイスではサポートされません。
アプリケーションにパッチするには、以下を行います。
スクリプトファイルを更新します。
注意: ゲームオブジェクトにアタッチされたスクリプトのレイアウトを変更する場合 (新しい Public 変数の追加など)、Script Only Build とパッチ処理は失敗します。
エディターで、File> Build Settings をクリックします。
Build Type ドロップダウンから Development を選択します。
IL2CPP スクリプティングバックエンドを使用している場合は、以下を行います (そうでない場合は次のステップに進みます)。
Scripts Only Build チェックボックスをチェックします。
Patch または Patch & Run をクリックします。
更新したスクリプトファイルをビルドした後、Unity は更新したファイルを Run Device フィールドで指定されたデバイスに送信します。
独自のビルドパイプラインを実装している場合は、スクリプティング API を使用して BuildOptions.BuildScriptsOnly
と BuildOptions.PatchPackage
オプションを BuildPipeline.BuildPlayer
メソッドに渡すことで、アプリケーションをパッチ処理します。
例:
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity"};
buildPlayerOptions.target = BuildTarget.Android;
//通常通りゲームをビルドして実行します。これは、アプリケーションを Android デバイスにインストールします。
buildPlayerOptions.options = BuildOptions.AutoRunPlayer
BuildPipeline.BuildPlayer(buildPlayerOptions);
//Unity プロジェクトのスクリプトの一部を変更します
// アプリケーションをパッチして実行します
// (Unity はスクリプトファイルのみを再コンパイルして、必要なファイルのみを Android デバイスにプッシュします)
buildPlayerOptions.options = BuildOptions.BuildScriptsOnly | BuildOptions.PatchPackage | BuildOptions.AutoRunPlayer;
BuildPipeline.BuildPlayer(buildPlayerOptions);
Unity は更新されたスクリプトを含むファイルをアプリケーションのキャッシュフォルダーに送信します。アプリケーションが起動すると、ファイルを読み込む前にキャッシュフォルダーをチェックします。アプリケーションが必要なファイルを見つけると、アプリケーションのデータ フォルダーの代わりにキャッシュフォルダーのファイルが読み込まれます。
Unity が送信するファイルは、使用しているスクリプティングバックエンドによって異なります。
プロジェクトのスクリプトファイル、パッケージのスクリプトファイル、または asmdef ファイルからコンパイルされたマネージアセンブリは /storage/emulated/0/Android/data/<PackageName>/cache/ScriptOnly/<UnityVersion>/mono/Managed に送信されます。
libil2cpp.so は /data/data/<PackageName>/cache/ScriptOnly/<UnityVersion>/il2cpp に送信されます。
注意: これは内部キャッシュです。 Android 7.0 で導入されたセキュリティ強化のため、エミュレートされたストレージから動的ライブラリをロードすることはできません。詳細は、Android 開発者 向けウェブサイトの Android 7.0 の動作の変更点 を参照してください。
IL2CPP リソースファイルは /storage/emulated/0/Android/data/<PackageName>/cache/ScriptOnly/<UnityVersion>/il2cpp に送信されます。
Android のストレージ設定を使用して、アプリケーションのキャッシュをクリアし、Script Only ビルドプロセスによってインストールされたパッチファイルを削除することができます。デバイスのキャッシュをクリアするには、設定に移動し、アプリケーションリストを開きます。通常、保存されたデータやキャッシュをクリアするオプションがあります。Android OS の実装によっては、キャッシュをクリアするオプションを見つけるために、ストレージオプションにドリルダウンする必要がある場合があります。
2018–11–13 公開ページ
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.