Пример #1
0
        static void AfterBuild(BuildTarget target, bool isDebug = false)
        {
            // SDKEditor.SetFirebase();
            // PluginConfigInfo info = PluginsInfoManager.LoadPluginConfig();

            // if (info != null && info.m_Map.ContainsKey(Constants.FaceBook))
            // {
            //     FacebookConfigInfo fbInfo = info.m_Map[Constants.FaceBook] as FacebookConfigInfo;
            //     SDKEditor.SetFacebook(fbInfo.AppID);
            // }

#if !UNITY_2019_1_OR_NEWER
            //所有项目已经弃用 2018.4以下,2019.2以下版本。NDK统一为r16b,以下代码已无用。
            //if (!EditorPrefs.HasKey("AndroidNdkRoot") && string.IsNullOrEmpty(EditorPrefs.GetString("AndroidNdkRoot")))
            //{
            //    EditorPrefs.SetString("AndroidNdkRoot", "/Users/dragonplus/Downloads/android-ndk-r13b");
            //}

            //if (!EditorPrefs.HasKey("JdkPath") || string.IsNullOrEmpty(EditorPrefs.GetString("JdkPath")))
            //{
            //    EditorPrefs.SetString("JdkPath", "/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/");
            //}

            //if (!EditorPrefs.HasKey("AndroidSdkRoot") || string.IsNullOrEmpty(EditorPrefs.GetString("AndroidSdkRoot")))
            //{
            //    EditorPrefs.SetString("AndroidSdkRoot", "/Users/dragonplus/Library/Android/sdk");
            //}
#endif
            // DebugUtil.Log("Android NDK Path is now {0}", EditorPrefs.GetString("AndroidNdkRoot"));

#if UNITY_2018_4_OR_NEWER || UNITY_2019_1_OR_NEWER
            //强制设置NDK版本
            //Unity修改本 key 为 AndroidNdkRootR16b,详见:https://forum.unity.com/threads/android-ndk-path-editorprefs-key-changed.639103/
            if (!EditorPrefs.HasKey("AndroidNdkRoot") || string.IsNullOrEmpty(EditorPrefs.GetString("AndroidNdkRoot")))
            {
                EditorPrefs.SetString("AndroidNdkRoot", "/Users/dragonplus/Downloads/android-ndk-r16b");
            }
            if (!EditorPrefs.HasKey("AndroidNdkRootR16b") || string.IsNullOrEmpty(EditorPrefs.GetString("AndroidNdkRootR16b")))
            {
                EditorPrefs.SetString("AndroidNdkRootR16b", "/Users/dragonplus/Downloads/android-ndk-r16b");
            }
#endif

#if UNITY_2019_3_OR_NEWER
            if (!EditorPrefs.HasKey("AndroidNdkRootR19") || string.IsNullOrEmpty(EditorPrefs.GetString("AndroidNdkRootR19")))
            {
                EditorPrefs.SetString("AndroidNdkRootR19", "/Users/dragonplus/Downloads/android-ndk-r19");
            }
#endif


            BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
            buildPlayerOptions.scenes = GetScenes();

            PlayerSettings.SplashScreen.showUnityLogo = false;

            string platform       = "";
            string platformFolder = "";
            if (target == BuildTarget.Android)
            {
                platform = "Android";

                EditorUserBuildSettings.androidCreateSymbolsZip = false;
                if (!isDebug)
                {
                    EditorUserBuildSettings.androidCreateSymbolsZip = true;

                    //PlayerSettings.Android.keystoreName = "/Users/dragonplus/flydragon.keystore";
                    //PlayerSettings.Android.keystorePass = "******";
                    //PlayerSettings.Android.keyaliasName = "flydragon.keystore";
                    //PlayerSettings.Android.keyaliasPass = "******";

#if UNITY_2019_1_OR_NEWER
                    PlayerSettings.Android.useCustomKeystore = true;
#endif

                    if (ConfigurationController.Instance.AndroidKeyStoreUseConfiguration)
                    {
                        PlayerSettings.Android.keystoreName = ConfigurationController.Instance.AndroidKeyStorePath;
                        PlayerSettings.Android.keystorePass = ConfigurationController.Instance.AndroidKeyStorePass;
                        PlayerSettings.Android.keyaliasName = ConfigurationController.Instance.AndroidKeyStoreAlias;
                        PlayerSettings.Android.keyaliasPass = ConfigurationController.Instance.AndroidKeyStoreAliasPass;
                    }
                    else
                    {
#if !UNITY_2019_1_OR_NEWER
                        PlayerSettings.Android.keystoreName = "/Users/dragonplus/smartfunapp.keystore";
                        PlayerSettings.Android.keystorePass = "******";
                        PlayerSettings.Android.keyaliasName = "SmartFun.keystore";
                        PlayerSettings.Android.keyaliasPass = "******";
#endif
                    }
                }

#if UNITY_2019_1_OR_NEWER
                DebugUtil.Log("useCustomKeystore is " + PlayerSettings.Android.useCustomKeystore);
#endif
                DebugUtil.Log("PlayerSettings.Android.keystoreName is " + PlayerSettings.Android.keystoreName);
                DebugUtil.Log("PlayerSettings.Android.keystorePass is " + PlayerSettings.Android.keystorePass);
                DebugUtil.Log("PlayerSettings.Android.keyaliasName is " + PlayerSettings.Android.keyaliasName);
                DebugUtil.Log("PlayerSettings.Android.keyaliasPass is " + PlayerSettings.Android.keyaliasPass);

#if UNITY_2018_4_OR_NEWER || UNITY_2019_1_OR_NEWER
                if (ConfigurationController.Instance.BuildAppBundle)
                {
                    EditorUserBuildSettings.buildAppBundle = true;
                }
                else
                {
                    EditorUserBuildSettings.buildAppBundle = false;
                }
#endif
            }
            else if (target == BuildTarget.iOS)
            {
                platform = "iOS";
                PlayerSettings.iOS.appleEnableAutomaticSigning = true;
            }
            platformFolder = Path.GetFullPath(Application.dataPath + "/../" + platform + "/build/");
            if (!Directory.Exists(platformFolder))
            {
                Directory.CreateDirectory(platformFolder);
            }

            if (target == BuildTarget.Android)
            {
#if UNITY_2018_4_OR_NEWER || UNITY_2019_1_OR_NEWER
                if (ConfigurationController.Instance.BuildAppBundle)
                {
                    platformFolder = platformFolder + PlayerSettings.productName + ".aab";
                }
                else
                {
                    platformFolder = platformFolder + PlayerSettings.productName + ".apk";
                }
#else
                platformFolder = platformFolder + PlayerSettings.productName + ".apk";
#endif
            }

            if (target == BuildTarget.StandaloneOSX)
            {
                platformFolder = platformFolder + PlayerSettings.productName + ".app";
            }

            buildPlayerOptions.locationPathName = platformFolder;


            buildPlayerOptions.target = target;
            if (isDebug)
            {
                buildPlayerOptions.options |= BuildOptions.Development;
            }
            //else
            //{
            //    buildPlayerOptions.options = BuildOptions.None;
            //}

            BuildReport  report  = BuildPipeline.BuildPlayer(buildPlayerOptions);
            BuildSummary summary = report.summary;
            DebugUtil.Log(summary.result.ToString());
        }