public static void OnPostProcessBuild(BuildTarget target, string path)
        {
            if (target == BuildTarget.Android)
            {
                // Only allow builds for Gradle for Android
                // Native video surfaces are broken with internal builds
                AndroidBuildSystem currentBuildSystem = EditorUserBuildSettings.androidBuildSystem;
                if (currentBuildSystem != AndroidBuildSystem.Gradle)
                {
                    throw new PlatformNotSupportedException("Audience Network SDK must be built with Gradle. " +
                                                            "Switch build system to \"Gradle (New)\" under Build Settings.");
                }

                var defaultIdentifier = "com.Company.ProductName";

                // Find application identifier (backwards compatible prior to Unity 5.6)
                if (Utility.GetApplicationIdentifier() == defaultIdentifier)
                {
                    Debug.LogError("The default Unity Bundle Identifier (com.Company.ProductName) will not work correctly.");
                }

                if (!ManifestMod.CheckManifest())
                {
                    // If something is wrong with the Android Manifest, try to regenerate it to fix it for the next build.
                    ManifestMod.GenerateManifest();
                }
            }
            else if (target == BuildTarget.iOS)
            {
                ConfigurePluginPlatforms();
            }
        }
Esempio n. 2
0
        private static void AddPermission(XmlDocument doc,
                                          XmlNode xmlNode,
                                          string ns,
                                          string permissionName)
        {
            XmlElement element = CreatePermissionElement(doc, ns, permissionName);

            ManifestMod.SetOrReplaceXmlElement(xmlNode, element);
        }
Esempio n. 3
0
        private static void AddSimpleActivity(XmlDocument doc,
                                              XmlNode xmlNode,
                                              string ns,
                                              string className,
                                              Dictionary <string, string> customOptions = null,
                                              bool export = false)
        {
            XmlElement element = CreateActivityElement(doc, ns, className, customOptions, export);

            ManifestMod.SetOrReplaceXmlElement(xmlNode, element);
        }
        private static void RegenerateManifest()
        {
            bool updateManifest = EditorUtility.DisplayDialog(title,
                                  "Are you sure you want to regenerate your Android Manifest.xml?",
                                  "Okay",
                                  "Cancel");

            if (updateManifest) {
                ManifestMod.GenerateManifest();
                EditorUtility.DisplayDialog(title, "Android Manifest updated. \n \n If interstitial ads still throw ActivityNotFoundException, " +
                                            "you may need to copy the generated manifest at " + ManifestMod.AndroidManifestPath + " to /Assets/Plugins/Android.", "Okay");
            }
        }
Esempio n. 5
0
        public static void GenerateManifest()
        {
            var outputFile = 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);
        }
Esempio n. 6
0
        public static void UpdateManifest(string fullPath)
        {
            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");

            ManifestMod.AddPermission(doc, manNode, ns, "android.permission.INTERNET");
            ManifestMod.AddPermission(doc, manNode, ns, "android.permission.ACCESS_NETWORK_STATE");

            var configOptions = new Dictionary <string, string> ();

            configOptions.Add("configChanges", "keyboardHidden|orientation|screenSize");
            ManifestMod.AddSimpleActivity(doc, dict, ns, InterstitialActivityName, configOptions);

            // 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);
            }
        }
Esempio n. 7
0
        public static bool CheckManifest()
        {
            bool result     = true;
            var  outputFile = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");

            if (!File.Exists(outputFile))
            {
                Debug.LogError("An android manifest must be generated for the Audience Network SDK to work.  " +
                               "Go to Tools->Audience Network 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, InterstitialActivityName, out loginElement))
            {
                Debug.LogError(string.Format("{0} is missing from your android manifest.  " +
                                             "Go to Tools->Audience Network and press \"Regenerate Android Manifest\"", InterstitialActivityName));
                result = false;
            }

            return(result);
        }
Esempio n. 8
0
        public static void OnPostProcessBuild(BuildTarget target, string path)
        {
            if (target == BuildTarget.Android)
            {
                // The default Bundle Identifier for Unity does magical things that causes bad stuff to happen
                if (PlayerSettings.applicationIdentifier == "com.Company.ProductName")
                {
                    Debug.LogError("The default Unity Bundle Identifier (com.Company.ProductName) will not work correctly.");
                }

                if (!ManifestMod.CheckManifest())
                {
                    // If something is wrong with the Android Manifest, try to regenerate it to fix it for the next build.
                    ManifestMod.GenerateManifest();
                }
            }
            else if (target == BuildTarget.iOS)
            {
                ConfigurePluginPlatforms();
            }
        }
Esempio n. 9
0
        // Exporting the *.unityPackage for Asset store
        public static bool ExportPackage()
        {
            // Check that SDKs are built
            bool iOSFound     = File.Exists(AudienceNetworkPluginiOSPath);
            bool androidFound = File.Exists(AudienceNetworkPluginAndroidPath);

            if (!iOSFound || !androidFound)
            {
                Debug.Log("Exporting failed, no AN SDK build found. Found SDKS - iOS: " + iOSFound + " Android: " + androidFound);
                return(false);
            }


            try
            {
                AssetDatabase.DeleteAsset(PluginsPath + "Android/AndroidManifest.xml");
                AssetDatabase.DeleteAsset(PluginsPath + "Android/AndroidManifest.xml.meta");
                AssetDatabase.DeleteAsset(AudienceNetworkPluginsPath + "Android/AndroidManifest.xml");
                AssetDatabase.DeleteAsset(AudienceNetworkPluginsPath + "Android/AndroidManifest.xml.meta");

                string[] facebookFiles = Directory.GetFiles(AudienceNetworkPath, "*.*", SearchOption.AllDirectories);
                string[] pluginsFiles  = Directory.GetFiles(AudienceNetworkPluginsPath, "*.*", SearchOption.AllDirectories);
                string[] files         = new string[facebookFiles.Length + pluginsFiles.Length];

                facebookFiles.CopyTo(files, 0);
                pluginsFiles.CopyTo(files, facebookFiles.Length);

                AssetDatabase.ExportPackage(
                    files,
                    UnityPackagePath,
                    ExportPackageOptions.IncludeDependencies | ExportPackageOptions.Recurse);
            }
            finally
            {
                // regenerate the manifest
                ManifestMod.GenerateManifest();
            }
            return(true);
        }
        public static void OnPostProcessBuild(BuildTarget target, string path)
        {
            // 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);
            }

            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 (!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 OnPostProcessBuild(BuildTarget target, string path)
        {
            if (target == BuildTarget.Android)
            {
                var defaultIdentifier = "com.Company.ProductName";

                // Find application identifier (backwards compatible prior to Unity 5.6)
                if (Utility.GetApplicationIdentifier() == defaultIdentifier)
                {
                    Debug.LogError("The default Unity Bundle Identifier (com.Company.ProductName) will not work correctly.");
                }

                if (!ManifestMod.CheckManifest())
                {
                    // If something is wrong with the Android Manifest, try to regenerate it to fix it for the next build.
                    ManifestMod.GenerateManifest();
                }
            }
            else if (target == BuildTarget.iOS)
            {
                ConfigurePluginPlatforms();
            }
        }