public static void GenerateAndroidManifest(bool needTokenPermissions)
        {
            string destFilename = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

            // Generate AndroidManifest.xml
            string manifestBody = GPGSUtil.ReadEditorTemplate("template-AndroidManifest");

            Dictionary <string, string> overrideValues = new Dictionary <string, string>();

            if (!needTokenPermissions)
            {
                overrideValues[TOKENPERMISSIONKEY]     = "";
                overrideValues[WEBCLIENTIDPLACEHOLDER] = "";
            }
            else
            {
                overrideValues[TOKENPERMISSIONKEY] = TokenPermissions;
            }

            foreach (KeyValuePair <string, string> ent in Replacements)
            {
                string value =
                    GPGSProjectSettings.Instance.Get(ent.Value, overrideValues);
                manifestBody = manifestBody.Replace(ent.Key, value);
            }

            GPGSUtil.WriteFile(destFilename, manifestBody);
            GPGSUtil.UpdateGameInfo();
        }
Пример #2
0
        /// <summary>
        /// Checks for the android manifest file exsistance.
        /// </summary>
        /// <returns><c>true</c>, if the file exists <c>false</c> otherwise.</returns>
        public static bool AndroidManifestExists()
        {
            string destFilename = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

            return(File.Exists(destFilename));
        }
Пример #3
0
        public static void CopySupportLibs()
        {
            string sdkPath        = GetAndroidSdkPath();
            string supportJarPath = sdkPath +
                                    GPGSUtil.SlashesToPlatformSeparator(
                "/extras/android/support/v4/android-support-v4.jar");
            string supportJarDest =
                GPGSUtil.SlashesToPlatformSeparator("Assets/Plugins/Android/libs/android-support-v4.jar");

            string libProjPath = sdkPath +
                                 GPGSUtil.SlashesToPlatformSeparator(
                "/extras/google/google_play_services/libproject/google-play-services_lib");

            string libProjAM =
                libProjPath + GPGSUtil.SlashesToPlatformSeparator("/AndroidManifest.xml");
            string libProjDestDir = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/google-play-services_lib");

            // check that the Google Play Services lib project is there
            if (!System.IO.Directory.Exists(libProjPath) || !System.IO.File.Exists(libProjAM))
            {
                Debug.LogError("Google Play Services lib project not found at: " + libProjPath);
                EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.LibProjNotFound,
                                            GPGSStrings.AndroidSetup.LibProjNotFoundBlurb, GPGSStrings.Ok);
                return;
            }

            // clear out the destination library project
            GPGSUtil.DeleteDirIfExists(libProjDestDir);

            // Copy Google Play Services library
            FileUtil.CopyFileOrDirectory(libProjPath, libProjDestDir);

            if (!System.IO.File.Exists(supportJarPath))
            {
                // check for the new location
                supportJarPath = sdkPath + GPGSUtil.SlashesToPlatformSeparator(
                    "/extras/android/support/v7/appcompat/libs/android-support-v4.jar");
                Debug.LogError("Android support library v4 not found at: " + supportJarPath);
                if (!System.IO.File.Exists(supportJarPath))
                {
                    EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SupportJarNotFound,
                                                GPGSStrings.AndroidSetup.SupportJarNotFoundBlurb, GPGSStrings.Ok);
                    return;
                }
            }

            // create needed directories
            GPGSUtil.EnsureDirExists("Assets/Plugins");
            GPGSUtil.EnsureDirExists("Assets/Plugins/Android");

            // Clear out any stale version of the support jar.
            File.Delete(supportJarDest);

            // Copy Android Support Library
            FileUtil.CopyFileOrDirectory(supportJarPath, supportJarDest);
        }
Пример #4
0
        public static void GenerateAndroidManifest()
        {
            string destFilename = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

            // Generate AndroidManifest.xml
            string appId           = GPGSProjectSettings.Instance.Get(APPIDKEY, string.Empty);
            string nearbyServiceId = GPGSProjectSettings.Instance.Get(SERVICEIDKEY, string.Empty);
            string manifestBody    = GPGSUtil.ReadEditorTemplate("template-AndroidManifest");

            manifestBody = manifestBody.Replace(APPIDPLACEHOLDER, appId);
            manifestBody = manifestBody.Replace(SERVICEIDPLACEHOLDER, nearbyServiceId);
            GPGSUtil.WriteFile(destFilename, manifestBody);
            GPGSUtil.UpdateGameInfo();
        }
Пример #5
0
        public static void MenuItemGooglePlayGamesAndroidSdk()
        {
            // check that Android SDK is there
            string sdkPath = GPGSUtil.GetAndroidSdkPath();

            if (!GPGSUtil.HasAndroidSdk())
            {
                EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SdkNotFound,
                                            GPGSStrings.AndroidSetup.SdkNotFoundBlurb, GPGSStrings.Ok);
                return;
            }

            bool launch = EditorUtility.DisplayDialog(
                GPGSStrings.ExternalLinks.GooglePlayGamesAndroidSdkTitle,
                GPGSStrings.ExternalLinks.GooglePlayGamesAndroidSdkBlurb, GPGSStrings.Yes,
                GPGSStrings.No);

            if (launch)
            {
                string exeName =
                    sdkPath + GPGSUtil.SlashesToPlatformSeparator("/tools/android");
                string altExeName =
                    sdkPath + GPGSUtil.SlashesToPlatformSeparator("/tools/android.exe");

                EditorUtility.DisplayDialog(
                    GPGSStrings.ExternalLinks.GooglePlayGamesAndroidSdkTitle,
                    GPGSStrings.ExternalLinks.GooglePlayGamesAndroidSdkInstructions,
                    GPGSStrings.Ok);

                if (System.IO.File.Exists(exeName))
                {
                    System.Diagnostics.Process.Start(exeName);
                }
                else if (System.IO.File.Exists(altExeName))
                {
                    System.Diagnostics.Process.Start(altExeName);
                }
                else
                {
                    EditorUtility.DisplayDialog(
                        GPGSStrings.ExternalLinks.GooglePlayGamesSdkTitle,
                        GPGSStrings.ExternalLinks.GooglePlayGamesAndroidSdkManagerFailed,
                        GPGSStrings.Ok);
                }
            }
        }
        //Provide static access to setup for facilitating automated builds.
        public static void PerformSetup(string appId)
        {
            string sdkPath     = GPGSUtil.GetAndroidSdkPath();
            string libProjPath = sdkPath +
                                 GPGSUtil.SlashesToPlatformSeparator(
                "/extras/google/google_play_services/libproject/google-play-services_lib");
            string libProjAM =
                libProjPath + GPGSUtil.SlashesToPlatformSeparator("/AndroidManifest.xml");
            string libProjDestDir = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/google-play-services_lib");
            string projAM = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

            GPGSProjectSettings.Instance.Set("proj.AppId", appId);
            GPGSProjectSettings.Instance.Save();

            // check for valid app id
            if (!GPGSUtil.LooksLikeValidAppId(appId))
            {
                GPGSUtil.Alert(GPGSStrings.Setup.AppIdError);
                return;
            }

            // check that Android SDK is there
            if (!GPGSUtil.HasAndroidSdk())
            {
                Debug.LogError("Android SDK not found.");
                EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SdkNotFound,
                                            GPGSStrings.AndroidSetup.SdkNotFoundBlurb, GPGSStrings.Ok);
                return;
            }

            // check that the Google Play Services lib project is there
            if (!System.IO.Directory.Exists(libProjPath) || !System.IO.File.Exists(libProjAM))
            {
                Debug.LogError("Google Play Services lib project not found at: " + libProjPath);
                EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.LibProjNotFound,
                                            GPGSStrings.AndroidSetup.LibProjNotFoundBlurb, GPGSStrings.Ok);
                return;
            }

            string supportJarPath = sdkPath +
                                    GPGSUtil.SlashesToPlatformSeparator(
                "/extras/android/support/v4/android-support-v4.jar");
            string supportJarDest =
                GPGSUtil.SlashesToPlatformSeparator("Assets/Plugins/Android/android-support-v4.jar");

            if (!System.IO.File.Exists(supportJarPath))
            {
                // check for the new location
                supportJarPath = sdkPath + GPGSUtil.SlashesToPlatformSeparator(
                    "/extras/android/support/v7/appcompat/libs/android-support-v4.jar");
                Debug.LogError("Android support library v4 not found at: " + supportJarPath);
                if (!System.IO.File.Exists(supportJarPath))
                {
                    EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SupportJarNotFound,
                                                GPGSStrings.AndroidSetup.SupportJarNotFoundBlurb, GPGSStrings.Ok);
                    return;
                }
            }

            // create needed directories
            EnsureDirExists("Assets/Plugins");
            EnsureDirExists("Assets/Plugins/Android");

            // clear out the destination library project
            DeleteDirIfExists(libProjDestDir);

            // Clear out any stale version of the support jar.
            System.IO.File.Delete(supportJarDest);

            // Copy Google Play Services library
            FileUtil.CopyFileOrDirectory(libProjPath, libProjDestDir);

            // Copy Android Support Library
            FileUtil.CopyFileOrDirectory(supportJarPath, supportJarDest);

            // Generate AndroidManifest.xml
            string manifestBody = GPGSUtil.ReadEditorTemplate("template-AndroidManifest");

            manifestBody = manifestBody.Replace("___APP_ID___", appId);
            GPGSUtil.WriteFile(projAM, manifestBody);
            GPGSUtil.UpdateGameInfo();

            // refresh assets, and we're done
            AssetDatabase.Refresh();
            GPGSProjectSettings.Instance.Set("android.SetupDone", true);
            GPGSProjectSettings.Instance.Save();
            EditorUtility.DisplayDialog(GPGSStrings.Success,
                                        GPGSStrings.AndroidSetup.SetupComplete, GPGSStrings.Ok);
        }
        public static void CopySupportLibs()
        {
            string sdkPath        = GetAndroidSdkPath();
            string supportJarPath = sdkPath +
                                    GPGSUtil.SlashesToPlatformSeparator(
                "/extras/android/support/v4/android-support-v4.jar");
            string supportJarDest =
                GPGSUtil.SlashesToPlatformSeparator("Assets/Plugins/Android/libs/android-support-v4.jar");

            string libProjPath = sdkPath +
                                 GPGSUtil.SlashesToPlatformSeparator(
                "/extras/google/google_play_services/libproject/google-play-services_lib");

            string libProjAM =
                libProjPath + GPGSUtil.SlashesToPlatformSeparator("/AndroidManifest.xml");
            string libProjDestDir = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/google-play-services_lib");

            // check that the Google Play Services lib project is there
            if (!System.IO.Directory.Exists(libProjPath) || !System.IO.File.Exists(libProjAM))
            {
                Debug.LogError("Google Play Services lib project not found at: " + libProjPath);
                EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.LibProjNotFound,
                                            GPGSStrings.AndroidSetup.LibProjNotFoundBlurb, GPGSStrings.Ok);
                return;
            }

            // check version
            int version = GetGPSVersion(libProjPath);

            if (version < 0)
            {
                Debug.LogError("Google Play Services lib version cannot be found!");
            }
            if (version < PluginVersion.MinGmsCoreVersionCode)
            {
                if (!EditorUtility.DisplayDialog(string.Format(
                                                     GPGSStrings.AndroidSetup.LibProjVerTooOld,
                                                     version, PluginVersion.MinGmsCoreVersionCode),
                                                 GPGSStrings.Ok, GPGSStrings.Cancel))
                {
                    Debug.LogError("Google Play Services lib is too old! " +
                                   " Found version " +
                                   version + " require at least version " +
                                   PluginVersion.MinGmsCoreVersionCode);
                    return;
                }
                Debug.Log("Ignoring the version mismatch and continuing the build.");
            }

            // clear out the destination library project
            GPGSUtil.DeleteDirIfExists(libProjDestDir);

            // Copy Google Play Services library
            FileUtil.CopyFileOrDirectory(libProjPath, libProjDestDir);

            if (!System.IO.File.Exists(supportJarPath))
            {
                // check for the new location
                supportJarPath = sdkPath + GPGSUtil.SlashesToPlatformSeparator(
                    "/extras/android/support/v7/appcompat/libs/android-support-v4.jar");
                Debug.LogError("Android support library v4 not found at: " + supportJarPath);
                if (!System.IO.File.Exists(supportJarPath))
                {
                    EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SupportJarNotFound,
                                                GPGSStrings.AndroidSetup.SupportJarNotFoundBlurb, GPGSStrings.Ok);
                    return;
                }
            }

            // create needed directories
            GPGSUtil.EnsureDirExists("Assets/Plugins");
            GPGSUtil.EnsureDirExists("Assets/Plugins/Android");

            // Clear out any stale version of the support jar.
            File.Delete(supportJarDest);

            // Copy Android Support Library
            FileUtil.CopyFileOrDirectory(supportJarPath, supportJarDest);
        }