Build an APK for unity using a command on the terminal
I have a Unity3d project (running on mac) and I am trying to create an android apk file from the command line. Is it doable?
Now I have a PerformBuild.cs file inside Assets / Editor
and I call inside it:
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);
However, only an Android project is created for this, not an apk.
Is it possible to directly generate the APK using the cs build script or will I need to generate the project, import it for eclipse and then build the apk?
thank
Additional Information:
Here is the complete method in my script
[UnityEditor.MenuItem("CUSTOM/Test Android Build Step")]
static void androidBuild ()
{
Debug.Log("Command line build android version\n------------------\n------------------");
string[] scenes = GetBuildScenes();
string path = GetBuildPathAndroid();
if(scenes == null || scenes.Length==0 || path == null)
return;
Debug.Log(string.Format("Path: \"{0}\"", path));
for(int i=0; i<scenes.Length; ++i)
{
Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
}
Debug.Log("Starting Android Build!");
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);
BuildPipeline.buil
}
and I call it from the command line using the following:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -quit -executeMethod PerformBuild.androidBuild
and I have sdk setup for android installed and configured.
source to share
Just remove AcceptExternalModificationsToPlayer
from BuildOptions
.
BuildOptions.AcceptExternalModificationsToPlayer
On Android, this option will create a new Eclipse project. Any existing changes to the Eclipse project settings will be discarded.
Source: http://docs.unity3d.com/ScriptReference/BuildOptions.AcceptExternalModificationsToPlayer.html
Okay, I have to admit it's not 100% clear from this, but it is a "switch" for change to directly create a file .apk
instead of creating an Android project.
So in your case, just change
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);
to
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.None);
You can take a look at all different BuildOptions
for example. if you want your build to be debuggable (so you can connect the MonoDevelop debugger to it => BuildOptions.Development | BuildOptions.AllowDebugging
)
Source: http://docs.unity3d.com/ScriptReference/BuildOptions.html
source to share