What is the right command to build a Unity project as an Android apk?
Using this command I'm able to compile for Windows:
"C:\Program Files\Unity\Hub\Editor\2019.4.29f1\Editor\Unity.exe"
-batchmode
-nographics
-projectPath "C:\Users\MyUser\MyGitRepo\MyUnityProject"
-buildWindowsPlayer "C:\Users\MyUser\Desktop\MyGame.exe"
-logFile
"C:\Users\MyUser\Desktop\build.log"
-quit
(This is a one line command)
However now I want to do the same for Android. What to I need to change?
-buildAndroidPlayer
did not work for me...
Update
This website has an overview of command line options. There are options for anything but Android
(eg -buildOSX64Player <pathname>
etc). I can
specify -buildTarget <name>
where would be android. But I still dont get any apk. Also it does not say to specify an output path
There was no simple command for me. I had to add a Build Script that specifies all scenes which are part of the game. The script has to be placed under "Assets/Editor" in order to be accessible from commandline:
using System;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class BuildScript
{
static void PerformBuild()
{
string[] defaultScene = {
"Assets/MyGame/Scenes/MyGame_TitleScene.unity",
"Assets/MyGame/Scenes/MyGame_MainScene.unity",
"Assets/MyGame/Scenes/MyGame_EpisodeScene.unity",
};
BuildPipeline.BuildPlayer(defaultScene, "MyGame.apk" ,
BuildTarget.Android, BuildOptions.None);
}
}
and build using
"C:\Program Files\Unity\Hub\Editor\2019.4.29f1\Editor\Unity.exe" -projectPath "path\to\my\Game" -executeMethod BuildScript.PerformBuild -logFile "MyGame\APKs\build.log"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With