- Home /
Run by run on android building
I have a problem that I have been having with building 64 bit games with unity (this is required to upload games onto the play store). I have tried using IL2CPP backend, as well as using ARM64 but always come up with errors.
I was wondering if someone could just write up an answer which contains all the instructions required to build an android project which will be accepted by Google.
Unity editor version: 2019.3.0b7
Answer by naviln · Oct 29, 2019 at 01:35 PM
It can be a bit of a moving target, as things can change on either end.
It also depends on what libs you are using in your project - some are difficult to link and need some custom attention, especially if you are going to use IL2CPP. Firstly, I would avoid using a Beta build of Unity for getting something to a store front (don't use 2019.3.0b7).
Get the latest stable build, and build it manually until you get it right, create a bug report if you get stuck (to the Unity team), once it starts working then invest some time to automate it with a build server (I use teamcity).
I am currently building an android bundle using command line, configured on my team city server, and works pretty well. I manually upload the android bundle to google play using the google play console. I have a few builds up on Google Play at the moment.
I don't have time to go through the entire setup, but here is my command line call to invoke the build:
cd "C:\Program Files\Unity\Hub\Editor\2019.2.10f1\Editor\Unity.exe" "%keystorepass%" -username example@gmail.com -password examplepassword -projectPath %cd%\WildWar3Client -quit -batchmode -executeMethod BuildPlayers.AndroidBuild -logFile "C:\Logs\UnityAndroidBuidLog.txt"
where %keystorepass% is the password i used for my keystore and alias, and %cd% is the project directory.
And here is the code in my project for building the android bundle. I only have one scene, you could add your own names, or do it dynamically, add better error handling, etc etc.
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEditor.Build.Reporting;
using System.IO;
//Build scripts
public class BuildPlayers : MonoBehaviour
{
#if UNITY_EDITOR
[MenuItem("Build/Build Android")]
#endif
public static void AndroidBuild()
{
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] { "Assets/Resources/Scenes/MainScene.unity" };
buildPlayerOptions.locationPathName = "WW3ClientAndroid.aab";
buildPlayerOptions.target = BuildTarget.Android;
buildPlayerOptions.targetGroup = BuildTargetGroup.Android;
buildPlayerOptions.options = BuildOptions.CompressWithLz4;
//skip x86. that doesn't work
AndroidArchitecture aac = AndroidArchitecture.ARM64 | AndroidArchitecture.ARMv7;
PlayerSettings.Android.targetArchitectures = aac;
//use this for all archs
//PlayerSettings.Android.targetArchitectures = AndroidArchitecture.All;
//for android, use this to build a bundle instead
EditorUserBuildSettings.buildAppBundle = true;
//if Unity version is lower than 2018, also may need to set:
//EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
//try and get cmd args
var argers = System.Environment.GetCommandLineArgs();
string password = "default";
//index 1 has the password
password = argers[1];
//set the keystore password.
PlayerSettings.keystorePass = password;
PlayerSettings.keyaliasPass = password;
BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
BuildSummary summary = report.summary;
if (summary.result == BuildResult.Succeeded)
{
Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
//can we just copy it to a google drive folder straight away?
//where is the file? here: buildfolder\wildwar3\WildWar3Client\WW3ClientAndroid
var clientPath = Application.dataPath.Replace("/Assets", "");
//the path is
clientPath = clientPath + "/WW3ClientAndroid.aab";
Debug.Log("Client Path: " + clientPath);
//copy it somewhere easily findable for manual upload to google play.
var destReleaseFilePath = @"C:\Users\Navil\Google Drive\Wild War 3\Builds\Android\WW3ClientAndroid.aab";
File.Copy(clientPath, destReleaseFilePath, true);
}
if (summary.result == BuildResult.Failed)
{
Debug.Log("Build failed");
}
}
}
I know there are some gaps, and you'll probably have to iterate a few times to get it right. Making it repeatable on a build server will save you a lot of headache and stress. Good luck, and if you have any specific questions just let me know.