简体   繁体   English

如何在Android Studio中验证AndroidManifest.xml?

[英]How is AndroidManifest.xml validated in android studio?

How does android studio validate AndroidManifest.xml and any activity xml? Android Studio如何验证AndroidManifest.xml和任何活动xml? I have read this post and this and know that there isn't an actual schema for android manifest. 我已阅读这个帖子和这个 ,知道没有为Android清单的实际模式。 But how does android studio or any tool that validates AndroidManifest.xml knows, what tags and elements are legal? 但是android studio或验证AndroidManifest.xml的任何工具如何知道,哪些标签和元素合法?

there isn't an actual schema for android manifest 没有用于Android清单的实际架构

I don't think this is correct. 我认为这是不正确的。 According to this answer : 根据这个答案

The schemas don't exist as an xml file. 模式不存在为xml文件。 Schemas are dependent upon what UI classes your program uses. 模式取决于程序使用的UI类。

While there isn't a schema defined directly in an XML file, the valid tags and attributes can be defined elsewhere, such as in the Java code which parses and inflates an XML layout. 虽然在XML文件中没有直接定义模式,但是可以在其他地方定义有效的标记和属性,例如在Java代码中解析和扩展XML布局。

Everything can be found on the https://android.googlesource.com . 一切都可以在https://android.googlesource.com上找到。

The manifest model is not written as .xsd file. 清单模型未写为.xsd文件。 Instead it is written as a group of objects. 而是将其写为一组对象。 The tree can be found here 这棵树可以在这里找到

If you start from Manifest you can see, that it has the references to Application , List<UsesPermission> , etc. The Application has references to android:name and android:label and List<Activity> and so on. 如果从Manifest开始,您将看到它具有对ApplicationList<UsesPermission>等的引用。 Applicationandroid:nameandroid:label以及List<Activity>引用。

A sample from Activity object: 来自Activity对象的示例:

@Attribute("name")
@Required
@Convert(PackageClassConverter.class)
@ExtendClass("android.app.Activity")
AndroidAttributeValue<PsiClass> getActivityClass();

As you can see this is the way, that Android Studio knows, that activity tag inside manifest must have a name. 正如您所看到的那样,Android Studio知道,清单中的activity标签必须具有名称。 Two annotations are used: 使用了两个注释:

@Attribute("name")
@Required

One of them is the name of .xml tag attribute, and the second one informs, that this attribute is required. 其中之一是.xml标记属性的名称,第二个则通知此属性是必需的。

The names of tags, that can be used inside manifest can be found here 可在清单中使用的标记名称可在此处找到

A helper class used by Android Studio to get manifest properties can be found here 可以在此处找到Android Studio用于获取清单属性的帮助程序类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM