Ejemplo n.º 1
0
        /// <summary>
        /// <see>
        ///     <cref>ScriptableObject.CreateInstance</cref>
        /// </see>
        ///     Wrapper
        /// <para>ScriptableObject 생성시 생성자에 PlayerSettings에서 Get할경우 Unity Exception이 남</para>
        /// </summary>
        public static BuildConfig CreateConfig()
        {
            BuildConfig pConfig = ScriptableObject.CreateInstance <BuildConfig>();

            pConfig.strProductName     = PlayerSettings.productName;
            pConfig.arrBuildSceneNames = Builder.GetEnabled_EditorScenes();

            pConfig.strAbsolute_BuildOutputFolderPath = Application.dataPath.Replace("/Assets", "") + "/Build";
            pConfig.bUse_DateTime_Suffix = true;

            pConfig.pAndroidSetting = AndroidSetting.CreateSetting();
            pConfig.pIOSSetting     = IOSSetting.CreateSetting();

            return(pConfig);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 打包APK
        /// </summary>
        static private (bool, string) BuildAPK(BuildMode mode, string outdir)
        {
            bool ret = false;

            //切换到Android
            BDEditorApplication.SwitchToAndroid();
            //删除il2cpp缓存
            //DeleteIL2cppCache();

            if (!BDEditorApplication.BDFrameworkEditorSetting.IsSetConfig())
            {
                //For ci
                throw new Exception("请注意设置apk keystore账号密码");
            }

            //模式
            AndroidSetting androidConfig = null;

            switch (mode)
            {
            case BuildMode.Debug:
            case BuildMode.UseCurrentConfigDebug:
            {
                androidConfig = BDEditorApplication.BDFrameworkEditorSetting.AndroidDebug;
            }
            break;

            case BuildMode.Release:
            case BuildMode.UseCurrentConfigRelease:
            {
                androidConfig = BDEditorApplication.BDFrameworkEditorSetting.Android;
            }
            break;
            }


            //秘钥相关
            var keystorePath = IPath.Combine(BApplication.ProjectRoot, androidConfig.keystoreName);

            if (!File.Exists(keystorePath))
            {
                //For ci
                throw new Exception("【keystore】不存在:" + keystorePath);
            }

            PlayerSettings.Android.keystoreName = keystorePath;
            PlayerSettings.keystorePass         = androidConfig.keystorePass;
            PlayerSettings.Android.keyaliasName = androidConfig.keyaliasName;
            PlayerSettings.keyaliasPass         = androidConfig.keyaliasPass;
            Debug.Log("【keystore】" + PlayerSettings.Android.keystoreName);
            //具体安卓的配置
            PlayerSettings.gcIncremental = true;
            PlayerSettings.Android.preferredInstallLocation = AndroidPreferredInstallLocation.Auto;
            //PlayerSettings.stripEngineCode = true;
            // if (PlayerSettings.GetManagedStrippingLevel(BuildTargetGroup.Android) == ManagedStrippingLevel.High)
            // {
            //PlayerSettings.SetManagedStrippingLevel(BuildTargetGroup.Android, ManagedStrippingLevel.Low);
            // }


            //开启符号表
            EditorUserBuildSettings.androidCreateSymbolsZip = true;
            //不同模式的设置
            // switch (mode)
            // {
            //     case BuildMode.Debug:
            //     {
            //
            //     }
            //         break;
            //     case BuildMode.Release:
            //     {
            //
            //     }
            //         break;
            // }
            //

            var outputPath = IPath.Combine(outdir, string.Format("{0}_{1}.apk", Application.identifier, mode.ToString()));

            //文件夹处理
            if (!Directory.Exists(outdir))
            {
                Directory.CreateDirectory(outdir);
            }

            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }

            //开始项目一键打包
            string[]     scenes = { SCENEPATH };
            BuildOptions opa    = BuildOptions.None;

            switch (mode)
            {
            case BuildMode.UseCurrentConfigDebug:
            case BuildMode.Debug:
            {
                opa = BuildOptions.CompressWithLz4HC | BuildOptions.Development | BuildOptions.AllowDebugging | BuildOptions.ConnectWithProfiler | BuildOptions.EnableDeepProfilingSupport;
            }
            break;

            case BuildMode.UseCurrentConfigRelease:
            case BuildMode.Release:
            {
                opa = BuildOptions.CompressWithLz4HC;
            }
            break;
            }

            //构建包体
            Debug.Log("------------->Begin build<------------");
            UnityEditor.BuildPipeline.BuildPlayer(scenes, outputPath, BuildTarget.Android, opa);
            Debug.Log("------------->End build<------------");

            //构建出判断
            if (File.Exists(outputPath))
            {
                Debug.Log("Build Success :" + outputPath);
                ret = true;
                EditorUtility.RevealInFinder(outputPath);
            }
            else
            {
                //For ci
                throw new Exception("【BDFramework】Package not exsit! -" + outputPath);
            }

            return(ret, outputPath);
        }