예제 #1
0
        public void TestConvertManifestToInstalled_WithUrl()
        {
            var doc = new XDocument(InstantManifestWithUrl);

            AndroidManifestHelper.ConvertManifestToInstalled(doc);
            AssertEquals(InstalledManifestWithUrl, doc);
        }
예제 #2
0
        public void TestCreateManifestXDocument()
        {
            // Note: can switch to "utf-8" by creating a custom StringWriter using Encoding.UTF8
            const string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<manifest xmlns:android=""http://schemas.android.com/apk/res/android"">
  <application>
    <activity android:name=""com.unity3d.player.UnityPlayerActivity"">
      <intent-filter>
        <action android:name=""android.intent.action.MAIN"" />
        <category android:name=""android.intent.category.LAUNCHER"" />
      </intent-filter>
    </activity>
  </application>
</manifest>";

            var doc = AndroidManifestHelper.CreateManifestXDocument();

            // Need to use Save() to obtain the "<?xml>" declaration since XDocument.ToString() omits this.
            var stringBuilder = new StringBuilder();

            using (var writer = new StringWriter(stringBuilder))
            {
                doc.Save(writer);
            }

            Assert.AreEqual(expected, stringBuilder.ToString());
        }
예제 #3
0
        public void TestConvertManifestToInstant_NoActivityElement()
        {
            var doc    = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute, new XElement(Application)));
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionOneMainActivity, result);
        }
예제 #4
0
    public void OnPreprocessBuild(BuildTarget target, string path)
    {
        string      manifest = Path.Combine(Application.dataPath, "Plugins/Android/XgPush/AndroidManifest.xml");
        XmlDocument doc      = new XmlDocument();

        doc.Load(manifest);

        XmlElement actionNode = AndroidManifestHelper.SearchNode(doc, "manifest/application/service/intent-filter/action");

        actionNode.SetAttribute("android:name", Application.identifier + ".PUSH_ACTION");

        XmlElement provider1 = AndroidManifestHelper.SearchNode(doc, "manifest/application/provider",
                                                                new KeyValuePair <string, string>("android:name", "com.tencent.android.tpush.XGPushProvider"));

        provider1.SetAttribute("android:authorities", Application.identifier + ".AUTH_XGPUSH");

        XmlElement provider2 = AndroidManifestHelper.SearchNode(doc, "manifest/application/provider",
                                                                new KeyValuePair <string, string>("android:name", "com.tencent.android.tpush.SettingsContentProvider"));

        provider2.SetAttribute("android:authorities", Application.identifier + ".TPUSH_PROVIDER");

        XmlElement provider3 = AndroidManifestHelper.SearchNode(doc, "manifest/application/provider",
                                                                new KeyValuePair <string, string>("android:name", "com.tencent.mid.api.MidProvider"));

        provider3.SetAttribute("android:authorities", Application.identifier + ".TENCENT.MID.V3");

        doc.Save(manifest);
    }
예제 #5
0
        public void TestConvertManifestToInstant_NoAndroidNamespace()
        {
            var doc    = new XDocument(new XElement(Manifest));
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionMissingXmlnsAndroid, result);
        }
예제 #6
0
        public void TestConvertManifestToInstant_NoManifestElement()
        {
            var doc    = new XDocument();
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionOneManifestElement, result);
        }
예제 #7
0
        /// <summary>
        /// Configures the project to prepare for building the specified scenes in an instant app.
        /// </summary>
        public static void ConfigureProject(string[] scenesInBuild)
        {
            var requiredPolicies = PlayInstantSettingPolicy.GetRequiredPolicies();

            foreach (var policy in requiredPolicies)
            {
                var policyChangeCompleted = policy.ChangeState();
                if (!policyChangeCompleted)
                {
                    throw new Exception(string.Format("Failed to change policy: {0}", policy.Name));
                }
            }

            SetTargetArchitectures();

            var manifestUpdater = AndroidManifestHelper.GetAndroidManifestUpdater();
            var errorMessage    = manifestUpdater.SwitchToInstant(null);

            if (errorMessage != null)
            {
                throw new Exception(string.Format("Error updating AndroidManifest.xml: {0}", errorMessage));
            }

            PlayInstantBuildConfiguration.AddScriptingDefineSymbol(
                PlaySignatureVerifier.SkipVerifyGooglePlayServicesScriptingDefineSymbol);
            PlayInstantBuildConfiguration.SaveConfiguration("", scenesInBuild, "");
            PlayInstantBuildConfiguration.SetInstantBuildType();
        }
예제 #8
0
        public void TestConvertManifestToInstant_WithUrl()
        {
            var doc    = new XDocument(InstalledManifestWithUrl);
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.IsNull(result);
            AssertEquals(InstantManifestWithUrl, doc);
        }
예제 #9
0
        public void TestConvertManifestToInstant_InvalidAndroidNamespace()
        {
            var doc = new XDocument(new XElement(Manifest,
                                                 new XAttribute(AndroidXmlns, XNamespace.Get("http://wrong.schema.com"))));
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionInvalidXmlnsAndroid, result);
        }
        public void TestConvertManifestToInstant_TwoPluginVersions()
        {
            var doc = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute,
                                                 new XElement(Application, PluginVersion, PluginVersion)));
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionOnePluginVersion, result);
        }
        public void TestHasCurrentPluginVersion_NoPluginVersion()
        {
            string errorMessage;
            var    doc = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute, new XElement(Application)));

            Assert.IsFalse(AndroidManifestHelper.HasCurrentPluginVersion(doc, out errorMessage));
            Assert.IsNull(errorMessage);
        }
        public void TestTestHasCurrentPluginVersion_NoApplicationElement()
        {
            string errorMessage;
            var    doc = new XDocument(new XElement(Manifest));

            Assert.IsFalse(AndroidManifestHelper.HasCurrentPluginVersion(doc, out errorMessage));
            Assert.AreEqual(AndroidManifestHelper.PreconditionOneApplicationElement, errorMessage);
        }
        /// <summary>
        /// Builds a Play Instant APK or AAB based on the specified options.
        /// Displays warning/error dialogs if there are issues during the build.
        /// </summary>
        /// <returns>True if the build succeeded, false if it failed or was cancelled.</returns>
        public static bool Build(BuildPlayerOptions buildPlayerOptions)
        {
            var checkInstantManifestResult = AndroidManifestHelper.GetAndroidManifestUpdater().CheckInstantManifest();

            if (checkInstantManifestResult != null)
            {
                DisplayBuildError(string.Format("Failed to update manifest: {0}", checkInstantManifestResult));
                return(false);
            }

            var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);

#if UNITY_2018_1_OR_NEWER
            switch (buildReport.summary.result)
            {
            case BuildResult.Cancelled:
                Debug.Log("Build cancelled");
                return(false);

            case BuildResult.Succeeded:
                // BuildPlayer can fail and still return BuildResult.Succeeded so detect by checking totalErrors.
                if (buildReport.summary.totalErrors > 0)
                {
                    // No need to display a message since Unity will already have done this.
                    return(false);
                }

                // Actual success.
                return(true);

            case BuildResult.Failed:
                DisplayBuildError(string.Format("Build failed with {0} error(s)", buildReport.summary.totalErrors));
                return(false);

            default:
                DisplayBuildError("Build failed with unknown error");
                return(false);
            }
#else
            if (string.IsNullOrEmpty(buildReport))
            {
                return(true);
            }

            // Check for intended build cancellation.
            if (buildReport == "Building Player was cancelled")
            {
                Debug.Log(buildReport);
            }
            else
            {
                DisplayBuildError(buildReport);
            }

            return(false);
#endif
        }
        public void TestTestHasCurrentPluginVersion_TwoPluginVersions()
        {
            string errorMessage;
            var    doc = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute,
                                                    new XElement(Application, PluginVersion, PluginVersion)));

            Assert.IsFalse(AndroidManifestHelper.HasCurrentPluginVersion(doc, out errorMessage));
            Assert.AreEqual(AndroidManifestHelper.PreconditionOnePluginVersion, errorMessage);
        }
예제 #15
0
        public void TestConvertManifestToInstant_TwoActivitiesWithMainLauncher()
        {
            var doc = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute,
                                                 new XElement(Application,
                                                              new XElement(Activity, new XAttribute(AndroidNameXName, "Activity1"), MainLauncherIntentFilter),
                                                              new XElement(Activity, new XAttribute(AndroidNameXName, "Activity2"), MainLauncherIntentFilter))));
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionOneMainActivity, result);
        }
    public void OnPreprocessBuild(BuildTarget target, string path)
    {
        string      manifest = Path.Combine(Application.dataPath, "Plugins/Android/Location/AndroidManifest.xml");
        XmlDocument doc      = new XmlDocument();

        doc.Load(manifest);
        XmlElement node = AndroidManifestHelper.SearchNode(doc, "manifest/application/meta-data"
                                                           , new KeyValuePair <string, string>("android:name", "com.baidu.lbsapi.API_KEY"));

        node.SetAttribute("android:value", Configs.AppKey);
        doc.Save(manifest);
    }
        public void TestHasCurrentPluginVersion_IncorrectPluginVersion()
        {
            string errorMessage;
            var    doc = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute,
                                                    new XElement(Application,
                                                                 new XElement(MetaData,
                                                                              new XAttribute(AndroidNameXName, PlayInstantUnityPluginVersion),
                                                                              new XAttribute(AndroidValueXName, "Incorrect Version")))));

            Assert.IsFalse(AndroidManifestHelper.HasCurrentPluginVersion(doc, out errorMessage));
            Assert.IsNull(errorMessage);
        }
        public void TestConvertManifestToInstant_TwoViewIntentFilters()
        {
            var doc = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute,
                                                 new XElement(Application,
                                                              new XElement(Activity,
                                                                           new XAttribute(AndroidNameXName, MainActivityName),
                                                                           MainLauncherIntentFilter,
                                                                           CreateViewIntentFilter("example.com", null),
                                                                           CreateViewIntentFilter("example2.com", null)))));
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionOneViewIntentFilter, result);
        }
        public void TestConvertManifestToInstant_TwoInstantModules()
        {
            var doc = new XDocument(new XElement(Manifest, AndroidNamespaceAttribute, DistributionNamespaceAttribute,
                                                 new XElement(Application,
                                                              new XElement(Activity,
                                                                           new XAttribute(AndroidNameXName, MainActivityName),
                                                                           MainLauncherIntentFilter)),
                                                 CreateDistributionModuleInstant(ValueTrue),
                                                 CreateDistributionModuleInstant("false")));
            var result = AndroidManifestHelper.ConvertManifestToInstant(doc, TestUri);

            Assert.AreEqual(AndroidManifestHelper.PreconditionOneModuleInstant, result);
        }