Example #1
0
        string[] BuildListOfNotificationCategoryGroupsName(IDictionary <string, string> categoryGroupsDict)
        {
            if (categoryGroupsDict == null)
            {
                return new string[] { EM_Constants.NoneSymbol }
            }
            ;

            var list = new string[categoryGroupsDict.Count + 1];

            // Add "None" as first item.
            list[0] = EM_Constants.NoneSymbol;

            // Copy keys from the dict.
            categoryGroupsDict.Keys.CopyTo(list, 1);

            return(list);
        }

        string GetNotificationCategoryNameFromId(IDictionary <string, string> dict, string id)
        {
            string name = string.Empty;

            if (string.IsNullOrEmpty(id))
            {
                name = EM_Constants.NoneSymbol;
            }
            else if (dict != null)
            {
                name = EM_EditorUtil.GetKeyForValue(dict, id);
            }

            return(name);
        }

        // Generate a static class containing constants of category IDs.
        void GenerateNotificationConstants()
        {
            // First create a hashtable containing all the names to be stored as constants.
            SerializedProperty userCategoriesProp = NotificationProperties.userCategories.property;

            // First check if there're duplicate IDs.
            string duplicateID = EM_EditorUtil.FindDuplicateFieldInArrayProperty(userCategoriesProp, NotificationCategory_Id);

            if (!string.IsNullOrEmpty(duplicateID))
            {
                EM_EditorUtil.Alert("Error: Duplicate IDs", "Found duplicate category ID of \"" + duplicateID + "\".");
                return;
            }

            // Proceed with adding resource keys.
            Hashtable resourceKeys = new Hashtable();

            // Add the category IDs.
            for (int i = 0; i < userCategoriesProp.arraySize; i++)
            {
                SerializedProperty element = userCategoriesProp.GetArrayElementAtIndex(i);
                string             id      = element.FindPropertyRelative(NotificationCategory_Id).stringValue;

                // Ignore all items with an empty ID.
                if (!string.IsNullOrEmpty(id))
                {
                    string key = "UserCategory_" + id;
                    resourceKeys.Add(key, id);
                }
            }

            if (resourceKeys.Count > 0)
            {
                // Now build the class.
                EM_EditorUtil.GenerateConstantsClass(
                    EM_Constants.GeneratedFolder,
                    EM_Constants.RootNameSpace + "." + EM_Constants.NotificationsConstantsClassName,
                    resourceKeys,
                    true
                    );
            }
            else
            {
                EM_EditorUtil.Alert("Constants Class Generation", "No user category has been defined or category ID is missing.");
            }
        }

        //----------------------------------------------------------------
        // Importing Android Notification Res Folder
        //----------------------------------------------------------------
        void ImportAndroidNotificationResFolder()
        {
            string selectedFolder = EditorUtility.OpenFolderPanel(null, notificationSelectedAndroidResFolder, null);

            if (!string.IsNullOrEmpty(selectedFolder))
            {
                // Some folder was selected.
                notificationSelectedAndroidResFolder = selectedFolder;

                // Build Android library from the selected folder.
                if (EM_EditorUtil.DisplayDialog(
                        "Building Android Resources",
                        "Please make sure the selected folder is correct before proceeding.\n" + notificationSelectedAndroidResFolder,
                        "Go Ahead",
                        "Cancel"))
                {
                    // Prepare the lib config.
                    var config = new EM_AndroidLibBuilder.AndroidLibConfig();
                    config.packageName             = EM_Constants.AndroidNativeNotificationPackageName;
                    config.targetLibFolderName     = EM_Constants.NotificationAndroidResFolderName;
                    config.targetContentFolderName = "res";

                    EM_AndroidLibBuilder.BuildAndroidLibFromFolder(
                        notificationSelectedAndroidResFolder,
                        config,
                        OnAndroidNotificationResBuildProgress,
                        OnAndroidNotificationResBuildNewStep,
                        OnAndroidNotificationResBuildComplete
                        );
                }
            }
        }

        void OnAndroidNotificationResBuildProgress(float progress)
        {
            // Display progress bar.
            EditorUtility.DisplayProgressBar(
                "Generating Android Notification Resources",
                notificationCreateAndroidResCurrentStep,
                progress
                );
        }

        void OnAndroidNotificationResBuildNewStep(string step)
        {
            notificationCreateAndroidResCurrentStep = step;
        }

        void OnAndroidNotificationResBuildComplete()
        {
            EditorUtility.ClearProgressBar();
            EM_EditorUtil.Alert(
                "Android Resources Imported",
                "Android notification resources have been imported successfully!"
                );
        }
    }
        internal static void GenerateManifest(string jdkPath, bool forceGenerate = false, bool verbose = false)
        {
            // First check if JDK is available.
            if (string.IsNullOrEmpty(jdkPath))
            {
                UnityEngine.Debug.LogError("JDK path is invalid. Aborting EM AndroidManifest generation...");
                return;
            }

            // Gather module manifests and merge them into one main manifest for EM.
            List <string> libPaths = new List <string>();

            //--------------------------------------Check for enable modules/ features---------------------------------------------------------//
            //Add more coditions to be checked and included when EasyMobile generates the main AndroidManifest.xml

            // Add the AndroidManifest template paths of all active modules and submodules.
            foreach (Module mod in Enum.GetValues(typeof(Module)))
            {
                var modulePaths = GetAndroidManifestTemplatePathsForModule(mod);
                if (modulePaths != null && modulePaths.Count > 0)
                {
                    libPaths.AddRange(modulePaths);
                }
            }

#if EASY_MOBILE_PRO
            // Add custom Android Manifest
            if (File.Exists(sCustomManifestPath))
            {
                libPaths.Add(sCustomManifestPath);
            }
#endif

            //---------------------------------------------------------------------------------------------------------------------------------//

            string libsPathsStr = "";
            foreach (var lib in libPaths)
            {
                // Fix issue if the path contains spaces
#if UNITY_EDITOR_WIN
                string actualPath = '"' + lib + '"';
#else
                string actualPath = "'" + lib + "'";
#endif
                libsPathsStr += " --libs " + actualPath;
            }

            // Stop if we have generated a manifest before and there's nothing new to added & not force generating.
            if (libsPathsStr == sLastTimeManifestLibsString && forceGenerate == false)
            {
                return;
            }

            var config = new EM_AndroidLibBuilder.AndroidLibConfig
            {
                packageName             = EM_Constants.AndroidNativePackageName,
                targetLibFolderName     = EM_Constants.EasyMobileAndroidResFolderName,
                targetContentFolderName = "res"
            };

            EM_AndroidLibBuilder.BuildAndroidLibFromFolder("", config, null, null, null,
                                                           (manifestPath) =>
            {
                string templatePath = FileIO.ToAbsolutePath("EasyMobile/Editor/Templates/Manifests/Manifest_Main.xml");
                string outputPath   = FileIO.ToAbsolutePath(manifestPath.Remove(0, 7));     // Remove "Assets/" from manifestPath
                string mexcPath     = FileIO.ToAbsolutePath("EasyMobile/Editor");

                sLastTimeManifestLibsString       = libsPathsStr;
                sMainManifestGeneratedSucessfully = true;

                if (verbose)
                {
                    UnityEngine.Debug.Log("Generating an Android manifest at\n" + outputPath + " \n");
                }

                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    WorkingDirectory       = mexcPath,
                };

                startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardError  = true;
                startInfo.UseShellExecute        = false;
                startInfo.CreateNoWindow         = true;
                startInfo.WorkingDirectory       = mexcPath;

                string javaPath = FileIO.SlashesToPlatformSeparator(Path.Combine(jdkPath, "bin/java"));
#if UNITY_EDITOR_WIN
                // Fix issue if paths contain spaces.
                string actualTemplatePath = '"' + templatePath + '"';
                string actualOutputPath   = '"' + outputPath + '"';
                string actualJavaPath     = '"' + javaPath + '"';

                startInfo.FileName = "cmd.exe";
                string command     = String.Format("\"{0} -cp .\\ManifMerger\\* com.android.manifmerger.Merger --main {1}{2} --out {3}\"",
                                                   actualJavaPath, actualTemplatePath, libsPathsStr, actualOutputPath); // it's vital to wrap the whole command in double quotes
                startInfo.Arguments = "/C " + command;
#else
                // Fix issue if paths contain spaces.
                string actualTemplatePath = "'" + templatePath + "'";
                string actualOutputPath   = "'" + outputPath + "'";
                string actualJavaPath     = "'" + javaPath + "'";

                string baseCommand = new StringBuilder().Append(actualJavaPath).
                                     Append(" -cp ./ManifMerger/annotations-12.0.jar:").
                                     Append("./ManifMerger/annotations-25.3.0.jar:").
                                     Append("./ManifMerger/bcpkix-jdk15on-1.48.jar:").
                                     Append("./ManifMerger/bcprov-jdk15on-1.48.jar:").
                                     Append("./ManifMerger/builder-model-2.3.0.jar:").
                                     Append("./ManifMerger/builder-test-api-2.3.0.jar:").
                                     Append("./ManifMerger/common-25.3.0.jar:").
                                     Append("./ManifMerger/commons-codec-1.4.jar:").
                                     Append("./ManifMerger/commons-compress-1.8.1.jar:").
                                     Append("./ManifMerger/commons-logging-1.1.1.jar:").
                                     Append("./ManifMerger/ddmlib-25.3.0.jar:").
                                     Append("./ManifMerger/dvlib-25.3.0.jar:").
                                     Append("./ManifMerger/gson-2.2.4.jar:").
                                     Append("./ManifMerger/guava-18.0.jar:").
                                     Append("./ManifMerger/httpclient-4.1.1.jar:").
                                     Append("./ManifMerger/httpcore-4.1.jar:").
                                     Append("./ManifMerger/httpmime-4.1.jar:").
                                     Append("./ManifMerger/jimfs-1.1.jar:").
                                     Append("./ManifMerger/kxml2-2.3.0.jar:").
                                     Append("./ManifMerger/layoutlib-api-25.3.0.jar:").
                                     Append("./ManifMerger/repository-25.3.0.jar:").
                                     Append("./ManifMerger/sdk-common-25.3.0.jar:").
                                     Append("./ManifMerger/sdklib-25.3.0.jar:").
                                     Append("./ManifMerger/manifest-merger-25.3.0.jar ").
                                     Append("com.android.manifmerger.Merger --main {0}{1} --out {2}").ToString();

                startInfo.FileName  = "/bin/bash";
                string command      = String.Format(baseCommand, actualTemplatePath, libsPathsStr, actualOutputPath);
                startInfo.Arguments = "-c \"" + command + "\"";
#endif

                Process process             = new Process();
                process.StartInfo           = startInfo;
                process.OutputDataReceived += OnConsoleDataReceived;
                process.ErrorDataReceived  += OnConsoleErrorReceived;
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }
                                                           );
        }