通过命令行构建Android Unity项目的简单命令

flseospp  于 2022-11-20  发布在  Android
关注(0)|答案(1)|浏览(107)

什么是正确的命令来构建一个Unity项目作为Android apk?
使用这个命令我可以编译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是单行命令)
然而现在我想为Android做同样的事情。我需要改变什么?

-buildAndroidPlayer

对我不起作用。

更新

This website有一个命令行选项的概述。有选项的任何东西,但Android(如-buildOSX64Player <pathname>等)。我可以指定-buildTarget <name>的地方将是Android。但我仍然没有得到任何apk。而且它没有说要指定一个输出路径

3b6akqbq

3b6akqbq1#

对我来说,没有简单的命令。我必须添加一个构建脚本,指定游戏中的所有场景:

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_World.unity",
            "Assets/MyGame/Scenes/MyGame_TitleScreen.unity",
            "Assets/MyGame/Scenes/MyGame_Character_Selection.unity",
            "Assets/MyGame/Scenes/MyGame_Episode_Content.unity",
            "Assets/MyGame/Scenes/MyGame_Episode_Selection.unity",
            "Assets/MyGame/Scenes/MyGame_Result.unity",
            "Assets/MyGame/Scenes/MyGame_Test.unity",
            "Assets/MyGame/Scenes/MyGame_Settings.unity",
            "Assets/MyGame/Scenes/MyGame_Mate_Selection.unity",
            };

        BuildPipeline.BuildPlayer(defaultScene, "MyGame.apk" ,
            BuildTarget.Android, BuildOptions.None);
    }

}

并使用

"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"

相关问题