/// <summary> /// Builds a single APK and places it in the build folder. /// </summary> /// <param name="settings">Description of the APK to build.</param> public static void BuildAPK(APKSettings settings) { // Don't make any permanent changes to the player settings! Texture2D[] oldIcons = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Android); string oldKeystoreName = PlayerSettings.Android.keystoreName; string oldkeyaliasName = PlayerSettings.Android.keyaliasName; string oldKeystorePass = PlayerSettings.Android.keystorePass; string oldKeyaliasPass = PlayerSettings.Android.keyaliasPass; string oldProductName = PlayerSettings.productName; string oldBundleIdentifier = PlayerSettings.bundleIdentifier; string oldAndroidSdkRoot = EditorPrefs.GetString("AndroidSdkRoot"); // make sure the product folder exists System.IO.Directory.CreateDirectory(BUILD_DIRECTORY_W_SLASH); // set icons (Android currently supports 6 sizes) Texture2D icon = (Texture2D)AssetDatabase.LoadMainAssetAtPath(ASSET_DIRECTORY_W_SLASH + settings.Icon); PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, new Texture2D[] { icon, icon, icon, icon, icon, icon }); string keystoreDir = FindKeystoreDirectory(); if (keystoreDir != null) { string keystorePass = ReadKeystorePassword(keystoreDir + "/trailmix-release-key-password.txt"); PlayerSettings.Android.keystoreName = keystoreDir + "/trailmix-release-key.keystore"; PlayerSettings.Android.keyaliasName = "alias_name"; PlayerSettings.Android.keystorePass = PlayerSettings.Android.keyaliasPass = keystorePass; } // set name and ids PlayerSettings.productName = settings.ProjectName; PlayerSettings.bundleIdentifier = settings.BundleIdentifier; // Unity won't remember where the Android SDK was when built on Jenkins string sdkRoot = Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT"); if (sdkRoot != String.Empty) { EditorPrefs.SetString("AndroidSdkRoot", sdkRoot); } // and finally... build it! string[] scenesUnityPath = new string[settings.Scenes.Length]; for (int it = 0; it != settings.Scenes.Length; ++it) { scenesUnityPath[it] = ASSET_DIRECTORY_W_SLASH + settings.Scenes[it]; } BuildPipeline.BuildPlayer(scenesUnityPath, BUILD_DIRECTORY_W_SLASH + settings.ProjectName + ".apk", BuildTarget.Android, BuildOptions.None); // Restore player settings PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, oldIcons); PlayerSettings.Android.keystoreName = oldKeystoreName; PlayerSettings.Android.keyaliasName = oldkeyaliasName; PlayerSettings.Android.keystorePass = oldKeystorePass; PlayerSettings.Android.keyaliasPass = oldKeyaliasPass; PlayerSettings.productName = oldProductName; PlayerSettings.bundleIdentifier = oldBundleIdentifier; EditorPrefs.SetString("AndroidSdkRoot", oldAndroidSdkRoot); }
/// <summary> /// Builds a single APK and places it in the build folder. /// </summary> /// <param name="settings">Description of the APK to build.</param> public static void BuildAPK(APKSettings settings) { // Don't make any permanent changes to the player settings! Texture2D[] oldIcons = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Android); string oldKeystoreName = PlayerSettings.Android.keystoreName; string oldkeyaliasName = PlayerSettings.Android.keyaliasName; string oldKeystorePass = PlayerSettings.Android.keystorePass; string oldKeyaliasPass = PlayerSettings.Android.keyaliasPass; string oldProductName = PlayerSettings.productName; string oldBundleIdentifier = PlayerSettings.bundleIdentifier; // make sure the product folder exists System.IO.Directory.CreateDirectory(BUILD_DIRECTORY_W_SLASH); // set icons (Android currently supports 6 sizes) Texture2D icon = (Texture2D)AssetDatabase.LoadMainAssetAtPath(ASSET_DIRECTORY_W_SLASH + settings.Icon); PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, new Texture2D[] { icon, icon, icon, icon, icon, icon }); string keystoreDir = FindKeystoreDirectory(); if (keystoreDir != null) { string keystorePass = ReadKeystorePassword(keystoreDir + "/trailmix-release-key-password.txt"); PlayerSettings.Android.keystoreName = keystoreDir + "/trailmix-release-key.keystore"; PlayerSettings.Android.keyaliasName = "alias_name"; PlayerSettings.Android.keystorePass = PlayerSettings.Android.keyaliasPass = keystorePass; } // set name and ids PlayerSettings.productName = settings.ProjectName; PlayerSettings.bundleIdentifier = settings.BundleIdentifier; // and finally... build it! string[] scenesUnityPath = new string[settings.Scenes.Length]; for (int it = 0; it != settings.Scenes.Length; ++it) { scenesUnityPath[it] = ASSET_DIRECTORY_W_SLASH + settings.Scenes[it]; } BuildPipeline.BuildPlayer(scenesUnityPath, BUILD_DIRECTORY_W_SLASH + settings.ProjectName + ".apk", BuildTarget.Android, BuildOptions.None); // Restore player settings PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, oldIcons); PlayerSettings.Android.keystoreName = oldKeystoreName; PlayerSettings.Android.keyaliasName = oldkeyaliasName; PlayerSettings.Android.keystorePass = oldKeystorePass; PlayerSettings.Android.keyaliasPass = oldKeyaliasPass; PlayerSettings.productName = oldProductName; PlayerSettings.bundleIdentifier = oldBundleIdentifier; }