使用Xamarin Android而不使用AndroidManifest.xml的属性(Using Xamarin Android without Using Attributes for Andro

系统教程 行业动态 更新时间:2024-06-14 17:02:18
使用Xamarin Android而不使用AndroidManifest.xml的属性(Using Xamarin Android without Using Attributes for AndroidManifest.xml)

我在Xamarin Android中创建了一个应用程序。 它具有自定义URI方案和通用链接支持,并且使用的特定URI方案和通用链接域是不同的,具体取决于我是否正在构建生产应用程序或用于QA目的的应用程序的测试版本。 这些设置最终作为intent过滤器在AndroidManifest.xml文件中结束。

Xamarin的文档表明,在开发Xamarin Android应用程序时,可以/应该使用自定义属性来指定Activity类的intent过滤器。 然后,Xamarin构建过程在构建时将这些转换为相关的XML部分,并将它们注入到AndroidManifest.xml文件中。

这很有用,但是当我使用自动构建过程在构建时交换这些intent过滤器的一些属性时,这有点限制。 理想情况下,我想自己手动控制AndroidManifest.xml文件的这些部分,因此我可以让我的构建脚本更新相关部分并直接添加/删除/更改意图过滤器部分。

我的问题是这是否可行和/或是否受到支持。 我可以简单地省略Activity类上的IntentFilterAttribute声明并将它们安全地设置在XML文件中吗? 或者,Xamarin是否要求我使用其过滤器属性,并且出于某种原因会避免出现问题?

I'm creating an app in Xamarin Android. It has a custom URI scheme and universal link support, and the specific URI schemes and universal link domains that are used are different depending on whether I'm building the production app or a test version of the app for QA purposes. These settings ultimately end up in the AndroidManifest.xml file as intent filters.

Xamarin's documentation indicates that when developing Xamarin Android apps, custom attributes can/should be used to specify the intent filters on the Activity classes. The Xamarin build process then converts these to the relevant XML sections at build time, and injects them into the AndroidManifest.xml file.

This is helpful, but it is a little restricting when I'm using an automated build process to swap out some of the properties of these intent filters at build time. Ideally, I'd like to control these sections of the AndroidManifest.xml file manually myself, so I can have my build script update the relevant sections and add/remove/change the intent filter sections directly.

My question is whether this is possible, and/or supported. Can I simply omit the IntentFilterAttribute declarations on my Activity class and set them in the XML file safely? Or, does Xamarin require that I use its filter attributes, and would avoiding this be problematic for some reason?

最满意答案

具有讽刺意味的是,我今天早上提出了一项关于高级清单合并的增强功能: https : //bugzilla.xamarin.com/show_bug.cgi? id = 52857

在XML文件和[Attribute]执行此操作的一个问题是,在构建时间之前不会生成其中一些项目(EX:您的<activity>元素)。 因此,更优选的是将其作为属性进行,以便在生成该元素时,它还知道要在其中放置什么样的过滤器。

如果你有一个构建过程找到正确的<activity>节点并在下面插入子节点,它可以工作,但它在Xamarin.Android构建系统中非常“容易出错”。

因此,虽然不需要属性,但出于安全原因,建议使用它们。 这些属性可以防止您通过手动AndroidManifest.xml修改来拍摄自己的脚。

Ironically, I filed an enhancement this morning regarding advanced manifest merging: https://bugzilla.xamarin.com/show_bug.cgi?id=52857

One problem with doing it in the XML file vs. the [Attribute] is that some of these items won't be generated until build time (EX: your <activity> element). Thus it is much more preferred to do it as an attribute so that when generating that element, it also knows what intent filters to put inside it.

If you have a build process which is finding the correct <activity> node and inserting the children below, it can work however it is very "error prone" in the Xamarin.Android build system.

So although the attributes are not required, they are recommended for safety reasons. These attributes prevent you from shooting your own foot with manual AndroidManifest.xml modifications.

更多推荐

Xamarin,intent,AndroidManifest,xml,过滤器,电脑培训,计算机培训,IT培训"/> <meta n

本文发布于:2023-04-21 18:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e6ccf58c64b3206ec7ff3e771e046c4e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   属性   Android   Xamarin   Attributes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!