Example #1
0
        private static void ResolveManifest(AN_AndroidBuildRequirements requirements)
        {
            var androidManifest = new AMM_AndroidManifest(AN_Settings.ANDROID_MANIFEST_FILE_PATH);

            var manifest    = androidManifest.Template;
            var application = manifest.ApplicationTemplate;

            //Removing not used activities
            List <AMM_ActivityTemplate> unusedActivities = new List <AMM_ActivityTemplate>();

            foreach (var pair in application.Activities)
            {
                var act = pair.Value;
                if (!requirements.HasActivityWithName(act.Name))
                {
                    unusedActivities.Add(act);
                }
            }


            foreach (var act in unusedActivities)
            {
                application.RemoveActivity(act);
            }


            //Add required activities
            foreach (var activity in requirements.Activities)
            {
                var act = application.GetOrCreateActivityWithName(activity.Name);
                foreach (var pair in activity.Values)
                {
                    act.SetValue(pair.Key, pair.Value);
                }
            }

            //application properties
            ResolveProperties(manifest, requirements.ManifestProperties);
            ResolveProperties(application, requirements.ApplicationProperties);


            //Removing not used permissions
            List <string> unusedPermissions = new List <string>();

            foreach (var perm in manifest.Permissions)
            {
                if (!requirements.HasPermissionWithName(perm.Name))
                {
                    unusedPermissions.Add(perm.Name);
                }
            }

            foreach (var perm in unusedPermissions)
            {
                manifest.RemovePermission(perm);
            }

            //Add required permission
            foreach (var permission in requirements.Permissions)
            {
                manifest.AddPermission(permission);
                // tpl.SetValue("tools:remove", "android:maxSdkVersion");
            }

            //TODO only save if there is chnaged to save
            androidManifest.SaveManifest();
        }