private static void AddAppLinkingActivity(XmlDocument doc, XmlNode xmlNode, string ns, List <string> schemes) { XmlElement element = ManifestMod.CreateActivityElement(doc, ns, AppLinkActivityName, true); foreach (var scheme in schemes) { // We have to create an intent filter for each scheme since an intent filter // can have only one data element. XmlElement intentFilter = doc.CreateElement("intent-filter"); var action = doc.CreateElement("action"); action.SetAttribute("name", ns, "android.intent.action.VIEW"); intentFilter.AppendChild(action); var category = doc.CreateElement("category"); category.SetAttribute("name", ns, "android.intent.category.DEFAULT"); intentFilter.AppendChild(category); XmlElement dataElement = doc.CreateElement("data"); dataElement.SetAttribute("scheme", ns, scheme); intentFilter.AppendChild(dataElement); element.AppendChild(intentFilter); } ManifestMod.SetOrReplaceXmlElement(xmlNode, element); }
public static void OnPostProcessBuild(BuildTarget target, string path) { // If integrating with facebook on any platform, throw a warning if the app id is invalid if (!Facebook.Unity.FacebookSettings.IsValidAppId) { Debug.LogWarning("You didn't specify a Facebook app ID. Please add one using the Facebook menu in the main Unity editor."); } // Unity renamed build target from iPhone to iOS in Unity 5, this keeps both versions happy if (target.ToString() == "iOS" || target.ToString() == "iPhone") { UpdatePlist(path); FixupFiles.FixSimulator(path); FixupFiles.AddVersionDefine(path); FixupFiles.FixColdStart(path); } if (target == BuildTarget.Android) { // The default Bundle Identifier for Unity does magical things that causes bad stuff to happen if (PlayerSettings.bundleIdentifier == "com.Company.ProductName") { Debug.LogError("The default Unity Bundle Identifier (com.Company.ProductName) will not work correctly."); } if (!FacebookAndroidUtil.IsSetupProperly()) { Debug.LogError("Your Android setup is not correct. See Settings in Facebook menu."); } if (!ManifestMod.CheckManifest()) { // If something is wrong with the Android Manifest, try to regenerate it to fix it for the next build. ManifestMod.GenerateManifest(); } } }
private static XmlElement CreateUnityOverlayElement(XmlDocument doc, string ns, string activityName) { // <activity android:name="activityName" android:configChanges="all|of|them" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"> // </activity> XmlElement activityElement = ManifestMod.CreateActivityElement(doc, ns, activityName); activityElement.SetAttribute("configChanges", ns, "fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"); activityElement.SetAttribute("theme", ns, "@android:style/Theme.Translucent.NoTitleBar.Fullscreen"); return(activityElement); }
private static XmlElement CreateLoginElement(XmlDocument doc, string ns) { // <activity android:name="com.facebook.LoginActivity" android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"> // </activity> XmlElement activityElement = ManifestMod.CreateActivityElement(doc, ns, LoginActivityName); activityElement.SetAttribute("configChanges", ns, "keyboardHidden|orientation"); activityElement.SetAttribute("theme", ns, "@android:style/Theme.Translucent.NoTitleBar.Fullscreen"); return(activityElement); }
private static XmlElement CreateFacebookElement(XmlDocument doc, string ns) { // <activity android:name="com.facebook.unity.FBUnityGameRequestActivity" android:exported="true"> // </activity> XmlElement activityElement = ManifestMod.CreateActivityElement(doc, ns, FacebookActivityName); activityElement.SetAttribute("configChanges", ns, "keyboard|keyboardHidden|screenLayout|screenSize|orientation"); activityElement.SetAttribute("label", ns, "@string/app_name"); activityElement.SetAttribute("theme", ns, "@android:style/Theme.Translucent.NoTitleBar"); return(activityElement); }
public static void OnPostProcessBuild(BuildTarget target, string path) { // If integrating with facebook on any platform, throw a warning if the app id is invalid if (!FBSettings.IsValidAppId) { Debug.LogWarning("You didn't specify a Facebook app ID. Please add one using the Facebook menu in the main Unity editor."); } #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 if (target == BuildTarget.iPhone) #else if (target == BuildTarget.iOS) #endif { UnityEditor.XCodeEditor.XCProject project = new UnityEditor.XCodeEditor.XCProject(path); // Find and run through all projmods files to patch the project string projModPath = System.IO.Path.Combine(Application.dataPath, "Facebook/Editor/iOS"); var files = System.IO.Directory.GetFiles(projModPath, "*.projmods", System.IO.SearchOption.AllDirectories); foreach (var file in files) { project.ApplyMod(Application.dataPath, file); } project.Save(); UpdatePlist(path); FixupFiles.FixSimulator(path); FixupFiles.AddVersionDefine(path); FixupFiles.FixColdStart(path); } if (target == BuildTarget.Android) { // The default Bundle Identifier for Unity does magical things that causes bad stuff to happen if (PlayerSettings.bundleIdentifier == "com.Company.ProductName") { Debug.LogError("The default Unity Bundle Identifier (com.Company.ProductName) will not work correctly."); } if (!FacebookAndroidUtil.IsSetupProperly()) { Debug.LogError("Your Android setup is not correct. See Settings in Facebook menu."); } if (!ManifestMod.CheckManifest()) { // If something is wrong with the Android Manifest, try to regenerate it to fix it for the next build. ManifestMod.GenerateManifest(); } } }
public static void GenerateManifest() { var outputFile = Path.Combine(Application.dataPath, ManifestMod.AndroidManifestPath); // Create containing directory if it does not exist Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); // only copy over a fresh copy of the AndroidManifest if one does not exist if (!File.Exists(outputFile)) { ManifestMod.CreateDefaultAndroidManifest(outputFile); } UpdateManifest(outputFile); }
public static bool CheckManifest() { bool result = true; var outputFile = Path.Combine(Application.dataPath, ManifestMod.AndroidManifestPath); if (!File.Exists(outputFile)) { Debug.LogError("An android manifest must be generated for the Facebook SDK to work. Go to Facebook->Edit Settings and press \"Regenerate Android Manifest\""); return(false); } XmlDocument doc = new XmlDocument(); doc.Load(outputFile); if (doc == null) { Debug.LogError("Couldn't load " + outputFile); return(false); } XmlNode manNode = FindChildNode(doc, "manifest"); XmlNode dict = FindChildNode(manNode, "application"); if (dict == null) { Debug.LogError("Error parsing " + outputFile); return(false); } XmlElement loginElement; if (!ManifestMod.TryFindElementWithAndroidName(dict, UnityLoginActivityName, out loginElement)) { Debug.LogError(string.Format("{0} is missing from your android manifest. Go to Facebook->Edit Settings and press \"Regenerate Android Manifest\"", UnityLoginActivityName)); result = false; } var deprecatedMainActivityName = "com.facebook.unity.FBUnityPlayerActivity"; XmlElement deprecatedElement; if (ManifestMod.TryFindElementWithAndroidName(dict, deprecatedMainActivityName, out deprecatedElement)) { Debug.LogWarning(string.Format("{0} is deprecated and no longer needed for the Facebook SDK. Feel free to use your own main activity or use the default \"com.unity3d.player.UnityPlayerNativeActivity\"", deprecatedMainActivityName)); } return(result); }
private static void AddSimpleActivity(XmlDocument doc, XmlNode xmlNode, string ns, string className, bool export = false) { XmlElement element = CreateActivityElement(doc, ns, className, export); ManifestMod.SetOrReplaceXmlElement(xmlNode, element); }
public static void UpdateManifest(string fullPath) { string appId = FacebookSettings.AppId; if (!FacebookSettings.IsValidAppId) { Debug.LogError("You didn't specify a Facebook app ID. Please add one using the Facebook menu in the main Unity editor."); return; } XmlDocument doc = new XmlDocument(); doc.Load(fullPath); if (doc == null) { Debug.LogError("Couldn't load " + fullPath); return; } XmlNode manNode = FindChildNode(doc, "manifest"); XmlNode dict = FindChildNode(manNode, "application"); if (dict == null) { Debug.LogError("Error parsing " + fullPath); return; } string ns = dict.GetNamespaceOfPrefix("android"); // add the unity login activity XmlElement unityLoginElement = CreateUnityOverlayElement(doc, ns, UnityLoginActivityName); ManifestMod.SetOrReplaceXmlElement(dict, unityLoginElement); // add the unity dialogs activity XmlElement unityDialogsElement = CreateUnityOverlayElement(doc, ns, UnityDialogsActivityName); ManifestMod.SetOrReplaceXmlElement(dict, unityDialogsElement); ManifestMod.AddAppLinkingActivity(doc, dict, ns, FacebookSettings.AppLinkSchemes[FacebookSettings.SelectedAppIndex].Schemes); ManifestMod.AddSimpleActivity(doc, dict, ns, DeepLinkingActivityName, true); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameRequestActivityName); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupCreateActivityName); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupJoinActivityName); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityAppInviteDialogActivityName); // add the app id // <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ fb<APPID>" /> XmlElement appIdElement = doc.CreateElement("meta-data"); appIdElement.SetAttribute("name", ns, ApplicationIdMetaDataName); appIdElement.SetAttribute("value", ns, "fb" + appId); ManifestMod.SetOrReplaceXmlElement(dict, appIdElement); // Add the facebook content provider // <provider // android:name="com.facebook.FacebookContentProvider" // android:authorities="com.facebook.app.FacebookContentProvider<APPID>" // android:exported="true" /> XmlElement contentProviderElement = CreateContentProviderElement(doc, ns, appId); ManifestMod.SetOrReplaceXmlElement(dict, contentProviderElement); // Remove the FacebookActivity since we can rely on it in the androidsdk aar as of v4.12 // (otherwise unity manifest merge likes fail if there's any difference at all) XmlElement facebookElement; if (TryFindElementWithAndroidName(dict, FacebookActivityName, out facebookElement)) { dict.RemoveChild(facebookElement); } // Save the document formatted XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", NewLineChars = "\r\n", NewLineHandling = NewLineHandling.Replace }; using (XmlWriter xmlWriter = XmlWriter.Create(fullPath, settings)) { doc.Save(xmlWriter); } }
public static void UpdateManifest(string fullPath) { //string appId = FacebookSettings.AppId; //if (!FacebookSettings.IsValidAppId) //{ // Debug.LogError("You didn't specify a Facebook app ID. Please add one using the Facebook menu in the main Unity editor."); // return; //} XmlDocument doc = new XmlDocument(); doc.Load(fullPath); if (doc == null) { Debug.LogError("Couldn't load " + fullPath); return; } XmlNode manNode = FindChildNode(doc, "manifest"); XmlNode dict = FindChildNode(manNode, "application"); if (dict == null) { Debug.LogError("Error parsing " + fullPath); return; } string ns = dict.GetNamespaceOfPrefix("android"); // add the unity login activity XmlElement unityLoginElement = CreateUnityOverlayElement(doc, ns, UnityLoginActivityName); ManifestMod.SetOrReplaceXmlElement(dict, unityLoginElement); // add the unity dialogs activity XmlElement unityDialogsElement = CreateUnityOverlayElement(doc, ns, UnityDialogsActivityName); ManifestMod.SetOrReplaceXmlElement(dict, unityDialogsElement); // add the login activity XmlElement loginElement = CreateLoginElement(doc, ns); ManifestMod.SetOrReplaceXmlElement(dict, loginElement); //ManifestMod.AddAppLinkingActivity(doc, dict, ns, FacebookSettings.AppLinkSchemes[FacebookSettings.SelectedAppIndex].Schemes); ManifestMod.AddSimpleActivity(doc, dict, ns, DeepLinkingActivityName, true); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameRequestActivityName); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupCreateActivityName); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupJoinActivityName); ManifestMod.AddSimpleActivity(doc, dict, ns, UnityAppInviteDialogActivityName); // add the app id // <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ fb<APPID>" /> XmlElement appIdElement = doc.CreateElement("meta-data"); appIdElement.SetAttribute("name", ns, ApplicationIdMetaDataName); //appIdElement.SetAttribute("value", ns, "fb" + appId); ManifestMod.SetOrReplaceXmlElement(dict, appIdElement); // Add the facebook content provider // <provider // android:name="com.facebook.FacebookContentProvider" // android:authorities="com.facebook.app.FacebookContentProvider<APPID>" // android:exported="true" /> //XmlElement contentProviderElement = CreateContentProviderElement(doc, ns, appId); //ManifestMod.SetOrReplaceXmlElement(dict, contentProviderElement); // Add the facebook activity // <activity // android:name="com.facebook.FacebookActivity" // android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" // android:label="@string/app_name" // android:theme="@android:style/Theme.Translucent.NoTitleBar" /> XmlElement facebookElement = CreateFacebookElement(doc, ns); ManifestMod.SetOrReplaceXmlElement(dict, facebookElement); // Save the document formatted XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", NewLineChars = "\r\n", NewLineHandling = NewLineHandling.Replace }; using (XmlWriter xmlWriter = XmlWriter.Create(fullPath, settings)) { doc.Save(xmlWriter); } }