Search Unity

Android export via command line fails

Discussion in 'Testing & Automation' started by viktorgottfried, Jan 20, 2021.

  1. viktorgottfried

    viktorgottfried

    Joined:
    Dec 29, 2020
    Posts:
    2
    I would like to perform the android export via command line. The export from the editor works as expected but if I run it via command line I get the following error:
    Executed command:
    ./Unity.exe -batchmode -nographics -logfile C:/tmp/unity.log -projectpath C:/Users/viktor/workspace/swcode/salzwelten-app/unity -executeMethod Assets.Editor.CIBuild.PerformAndroidBuild

    Build Script:
    Code (CSharp):
    1.     public class CIBuild : MonoBehaviour
    2.     {
    3.         static string[] SCENES = FindEnabledEditorScenes();
    4.  
    5.         [MenuItem("Custom/CI/Build iOS")]
    6.         static void PerformIOSBuild()
    7.         {
    8.             GenericBuild(SCENES, "iOSBuild", BuildTarget.iOS, BuildOptions.None, BuildTargetGroup.iOS);
    9.         }
    10.  
    11.         [MenuItem("Custom/CI/Build Android")]
    12.         static void PerformAndroidBuild()
    13.         {
    14.             GenericBuild(SCENES, "androidBuild", BuildTarget.Android, BuildOptions.None, BuildTargetGroup.Android);
    15.         }
    16.  
    17.         private static string[] FindEnabledEditorScenes()
    18.         {
    19.             List<string> EditorScenes = new List<string>();
    20.             foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
    21.             {
    22.                 if (!scene.enabled)
    23.                     continue;
    24.                 EditorScenes.Add(scene.path);
    25.             }
    26.             return EditorScenes.ToArray();
    27.         }
    28.  
    29.         static void GenericBuild(string[] scenes, string targetDir, BuildTarget buildTarget, BuildOptions build_options, BuildTargetGroup targetGroup)
    30.         {
    31.  
    32.             EditorUserBuildSettings.SwitchActiveBuildTarget(targetGroup, buildTarget);
    33.             BuildReport buildReport = BuildPipeline.BuildPlayer(scenes, targetDir, buildTarget, build_options);
    34.            
    35.             if (buildReport.summary.result == BuildResult.Succeeded)
    36.             {
    37.                 Debug.Log("Build succeeded");
    38.                 EditorApplication.Exit(0);
    39.             }
    40.  
    41.             if (buildReport.summary.result == BuildResult.Failed)
    42.             {
    43.                 Debug.Log("Build failed");
    44.                 EditorApplication.Exit(1);
    45.             }
    46.  
    47.         }
    48.     }
    The full build log is attached to the post.
     

    Attached Files:

  2. yuxirui010226

    yuxirui010226

    Joined:
    Feb 24, 2023
    Posts:
    2
    its depend on your project is export or build.

    You can try add
    Code (CSharp):
    1. EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
    this code to solve this error, even your question is two years ago.