简体   繁体   English

无法从Unity命令行生成Android APK

[英]Can't generate Android APK from Unity command line

When I run the following build script from commandline there are no errors in the build.log but also no APK is produced. 当我从命令行运行以下构建脚本时,build.log中没有错误,但也没有生成APK。 Occasionally I am am able to get a build using the exact same command with no added or changed files (I have check the folder diff using Meld). 偶尔我能够使用完全相同的命令获得构建,没有添加或更改的文件(我已经使用Meld检查文件夹差异)。

I seem to be more successful if I open and close unity but there are still no guarantees that it will build using command line. 如果我打开并关闭团结,我似乎更成功,但仍然无法保证它将使用命令行构建。 There is also added or changed files after closing unity. 关闭统一后,还会添加或更改文件。

It always works when running the build in unity through the GUI. 通过GUI统一运行构建时,它始终有效。

Windows command line: Windows命令行:

START /WAIT "" "C:\Program Files\Unity\Editor\Unity.exe" -batchmode -quit -executeMethod BuildScript.BuildAndroid -logfile build.log

I have also tried with -nographics to no avail 我也试过-nographics无济于事

BuildScript.cs: BuildScript.cs:

public class EditorSetup {
  public static string AndroidSdkRoot {
    get { return EditorPrefs.GetString("AndroidSdkRoot"); }
    set { EditorPrefs.SetString("AndroidSdkRoot", value); }
  }

  public static string JdkRoot {
    get { return EditorPrefs.GetString("JdkPath"); }
    set { EditorPrefs.SetString("JdkPath", value); }
  }

  // This requires Unity 5.3 or later
  public static string AndroidNdkRoot {
    get { return EditorPrefs.GetString("AndroidNdkRoot"); }
    set { EditorPrefs.SetString("AndroidNdkRoot", value); }
  }
}

public class BuildScript {
    public static string AndroidTitle = "Android"

    [MenuItem("Custom Build/Build AndroidHeadsetClient")]
    public static void BuildAndroid()
    {
        EditorSetup.AndroidSdkRoot = Environment.GetEnvironmentVariable("ANDROID_SDK_HOME");
        EditorSetup.JdkRoot = Environment.GetEnvironmentVariable("JDK_HOME");
        Debug.Log("JDK_HOME: " + EditorSetup.JdkRoot.ToString());
        Debug.Log("ANDROID_SDK_HOME: " + EditorSetup.AndroidSdkRoot.ToString());
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scenes/Main/" + AndroidTitle + ".unity" };
        buildPlayerOptions.locationPathName = "MyArtifact.apk";
        buildPlayerOptions.target = BuildTarget.Android;
        buildPlayerOptions.options = BuildOptions.None;
        BuildPipeline.BuildPlayer(buildPlayerOptions);
    }
}

File structure: 文件结构:

.
├── Assets
│   ├── Animations
│   │   ├── ...
│   ├── Animations.meta
│   ├── Animators
│   │   ├── ...
│   ├── Animators.meta
│   ├── AudioClips
│   │   ├── ...
│   ├── AudioClips.meta
│   ├── Data
│   │   ├── ...
│   ├── Data.meta
│   ├── Documents
│   │   ├── ...
│   ├── Documents.meta
│   ├── Editor
│   │   ├── BuildScript.cs
│   │   ├── BuildScript.cs.meta
│   │   ├── ...
└──...

Unity version: 5.6.1f1 Unity版本:5.6.1f1

Any help with this issue would be greatly appreciated. 任何有关此问题的帮助将不胜感激。

[Fixed] [固定]

This could happen because of multiple issues, and the real issue here is that, Unity batchmode doesn't show proper error logs in the console or log file. 这可能是由于多个问题而发生的,而真正的问题是,Unity batchmode在控制台或日志文件中没有显示正确的错误日志。

I removed the -batchmode option and ran the command. 我删除了-batchmode选项并运行命令。 Now the command is executed with Unity Editor opened. 现在,命令在Unity Editor打开时执行。 It will now show any errors, either in the log or as a popup. 它现在将显示任何错误,无论是在日志中还是作为弹出窗口。

My Issue: 我的问题:

In my case I forgot to change some keystore parameter, and unity showed me an error popup. 在我的情况下,我忘了更改一些keystore参数,团结向我显示错误弹出窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM