#!/usr/bin/python # Created by Egor Zubkov on 16/12/14. # Copyright 2014 NIX. All rights reserved. import argparse import os import sys import UnityBuildEnvVars default_configuration = "Debug" def main(): parser = argparse.ArgumentParser(description="Script builds Android build in Unity project.") parser.add_argument("--configuration", default=default_configuration) parser.add_argument("--unity-path", required=True) parser.add_argument("--development-build", action="store_true") parser.add_argument("--keystore-path") parser.add_argument("--keystore-password") parser.add_argument("--key-alias-name") parser.add_argument("--key-alias-password") args = parser.parse_args() if not args.unity_path: print "ERROR: unity_path must not be empty string!" exit(1) development_build_arg = args.development_build configuration_arg = args.configuration if configuration_arg != default_configuration: configuration_arg = "Release" development_build_arg = None if not args.keystore_path or not os.path.exists(args.keystore_path): print "ERROR: KeyStore file must exist!" exit(1) revision_number = UnityBuildEnvVars.revision_number() build_path = build_apk(revision_number, args.unity_path, development_build_arg, args.keystore_path, args.keystore_password, args.key_alias_name, args.key_alias_password) UnityBuildEnvVars.save_env_vars(configuration_arg, build_path) def build_apk(bundle_version, unity_path, development_build, keystore_path, keystore_password, key_alias_name, key_alias_password): build_path = os.path.join(os.getcwd(), "Builds/Android/Build.apk") build_path_arg = "buildPath=%s" % build_path bundle_version_arg = ";bundleVersionCode=%s" % bundle_version development_build_arg = "" if development_build == True: development_build_arg = ";developmentBuild=" keystore_path_arg = "" if keystore_path: keystore_path_arg = ";keyStorePath=%s" % keystore_path keystore_password_arg = "" if keystore_password: keystore_password_arg = ";keyStorePassword=%s" % keystore_password key_alias_name_arg = "" if key_alias_name: key_alias_name_arg = ";keyAliasName=%s" % key_alias_name key_alias_password_arg = "" if key_alias_password: key_alias_password_arg = ";keyAliasPassword=%s" % key_alias_password args = "'{0}' -projectPath '{1}' -executeMethod NIXBuilder.MakeAndroidBuild -batchmode -logFile -quit -customArgs:\"{2}{3}{4}{5}{6}{7}{8}\"".format(unity_path, os.getcwd(), build_path_arg, bundle_version_arg, development_build_arg, keystore_path_arg, keystore_password_arg, key_alias_name_arg, key_alias_password_arg) success = os.system(args) if success != 0: print "ERROR: build_apk failed!" exit(1) return build_path if __name__ == '__main__': sys.exit(main())