Last active
July 30, 2019 05:50
-
-
Save TsubameUnity/9a491e34f66f94853f43f4c1f829d877 to your computer and use it in GitHub Desktop.
Apkのビルドとインストールをメニューから選択orショートカットキーで出来るようにする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApkBuildAndInstall | |
{ | |
[MenuItem("ビルド/APK BuildInstall #b")] | |
static void BuildInstallApk() | |
{ | |
var path = System.Environment.CurrentDirectory; | |
var fullPath = Path.Combine(path, "test.apk"); | |
var levels = EditorBuildSettings.scenes.Where(x => x.enabled).Select(x => x.path).ToArray(); | |
PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup, ScriptingImplementation.Mono2x); | |
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARMv7 | AndroidArchitecture.X86; | |
EditorUserBuildSettings.buildAppBundle = false; | |
BuildPipeline.BuildPlayer(levels, fullPath, BuildTarget.Android, BuildOptions.None); | |
InstallApk(); | |
} | |
[MenuItem("ビルド/APK Install #i")] | |
static void InstallApk() | |
{ | |
var path = System.Environment.CurrentDirectory; | |
var fullPath = Path.Combine(path, "test.apk"); | |
var proc = new Process(); | |
proc.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec"); | |
proc.StartInfo.Arguments = $@"/k adb install -r {fullPath} & adb shell am start -n {PlayerSettings.GetApplicationIdentifier(EditorUserBuildSettings.selectedBuildTargetGroup)}/com.unity3d.player.UnityPlayerActivity & exit"; | |
proc.StartInfo.CreateNoWindow = true; | |
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | |
proc.Start(); | |
proc.WaitForExit(); | |
EditorUtility.DisplayDialog("ビルド", "インストール完了", "OK"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment