-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidBuild.cs
More file actions
59 lines (50 loc) · 1.73 KB
/
Copy pathAndroidBuild.cs
File metadata and controls
59 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2025 U.S. Federal Government (in countries where recognized)
// Copyright 2025 Dakota Crouchelli dakota.h.crouchelli.civ@us.navy.mil
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
namespace CREATIVE.UtilityEditor
{
/**
A class used for building an Android APK on the commandline
*/
public class AndroidBuild
{
/**
Builds an android APK.
This method should only be called by using the -executeMethod flag when
opening the editor on the commandline. The path to the APK should be
supplied after the method name, i.e.:
-executeMethod AndroidBuild.Build .\Build\myAndroidApp.apk
Documentation for the Unity Editor CLI can be found here:
https://docs.unity3d.com/Manual/EditorCommandLineArguments.html
*/
public static void Build()
{
String[] cmdArgs = Environment.GetCommandLineArgs();
string androidBuildPath = null;
for (int i=0; i<cmdArgs.Length; i++)
{
if (cmdArgs[i].Equals("-executeMethod") && (i+2)<cmdArgs.Length)
{
androidBuildPath = cmdArgs[i+2];
i+=2;
}
}
if (androidBuildPath == null)
throw new InvalidOperationException
(
"Android Build method was called," +
"but a path for an APK was not specified on the command line."
);
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = EditorBuildSettings.scenes.Select(scene => scene.path).ToArray();
buildPlayerOptions.locationPathName = androidBuildPath;
buildPlayerOptions.target = BuildTarget.Android;
buildPlayerOptions.options = BuildOptions.None;
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
}
}