public class ResourceNamespace extends java.lang.Object implements java.lang.Comparable<ResourceNamespace>, java.io.Serializable
In "traditional" projects, all resources from local sources and AARs live in the RES_AUTO namespace and are processed together by aapt. Framework resources belong in the
"android" package name / namespace.
In namespace-aware projects, every module and AAR contains resources in a separate namespace
that is read from the manifest and corresponds to the package-name. Framework resources
are treated as before.
The tools namespace is a special case and is only used by sample data, so it never reaches the aapt stage.
This class is serializable to allow passing between Gradle workers.
| Modifier and Type | Class and Description |
|---|---|
static interface |
ResourceNamespace.Resolver
Logic for looking up namespace prefixes defined in some context.
|
| Modifier and Type | Field and Description |
|---|---|
static ResourceNamespace |
AAPT |
static ResourceNamespace |
ANDROID |
static ResourceNamespace |
APPCOMPAT
The namespace of the Androidx appcompat library when namespaces are used.
|
static ResourceNamespace |
APPCOMPAT_LEGACY
The namespace of the old appcompat library when namespaces are used.
|
static boolean |
noncomplianceLogging |
static ResourceNamespace |
RES_AUTO |
static ResourceNamespace |
TOOLS |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(ResourceNamespace other) |
boolean |
equals(java.lang.Object o) |
static ResourceNamespace |
fromBoolean(boolean isFramework)
Deprecated.
|
static ResourceNamespace |
fromNamespacePrefix(java.lang.String prefix,
ResourceNamespace defaultNamespace,
ResourceNamespace.Resolver resolver)
Tries to build a
ResourceNamespace from the first part of a ResourceUrl, given the context in which the string was used. |
static ResourceNamespace |
fromNamespaceUri(java.lang.String uri)
Constructs a
ResourceNamespace for the given URI, as used in XML resource files. |
static ResourceNamespace |
fromPackageName(java.lang.String packageName)
Constructs a
ResourceNamespace for the given (fully qualified) aapt package name. |
java.lang.String |
getPackageName()
Returns the package associated with this namespace, or null in the case of
RES_AUTO. |
java.lang.String |
getXmlNamespaceUri() |
int |
hashCode() |
java.lang.Object |
readResolve() |
static ResourceNamespace |
TODO()
Namespace used in code that needs to start keeping track of namespaces.
|
java.lang.String |
toString() |
public static final ResourceNamespace ANDROID
public static final ResourceNamespace RES_AUTO
public static final ResourceNamespace TOOLS
public static final ResourceNamespace AAPT
public static final ResourceNamespace APPCOMPAT
public static final ResourceNamespace APPCOMPAT_LEGACY
public static boolean noncomplianceLogging
@NonNull public static ResourceNamespace TODO()
@NonNull public static ResourceNamespace fromPackageName(@NonNull java.lang.String packageName)
ResourceNamespace for the given (fully qualified) aapt package name.
Note that this is not the string used in XML notation before the colon (at least not in the
general case), which can be an alias.
This factory method can be used when reading the build system model or for testing, other code most likely needs to resolve the short namespace prefix against XML namespaces defined in the given context.
@NonNull @Deprecated public static ResourceNamespace fromBoolean(boolean isFramework)
ResourceNamespace in code that does not keep track of namespaces yet,
only of the boolean `isFramework` flag.@Nullable public static ResourceNamespace fromNamespacePrefix(@Nullable java.lang.String prefix, @NonNull ResourceNamespace defaultNamespace, @NonNull ResourceNamespace.Resolver resolver)
ResourceNamespace from the first part of a ResourceUrl, given the context in which the string was used.prefix - the string to resolvedefaultNamespace - namespace in which this prefix was used. If no prefix is used (it's
null), this is the namespace that will be returned. For example, if an XML file inside
libA (com.lib.a) references "@string/foo", it means the "foo" resource from libA, so the
"com.lib.a" namespace should be passed as the defaultNamespace.resolver - strategy for mapping short namespace prefixes to namespace URIs as used in
XML resource files. This should be provided by the XML parser used. For example, if the
source XML document contained snippet such as xmlns:foo="http://schemas.android.com/apk/res/com.foo", it should return "http://schemas.android.com/apk/res/com.foo" when applied to argument "foo".ResourceUrl.namespace@Nullable public static ResourceNamespace fromNamespaceUri(@NonNull java.lang.String uri)
ResourceNamespace for the given URI, as used in XML resource files.
This methods returns null if we don't recognize the URI.
@Nullable public java.lang.String getPackageName()
RES_AUTO.
The result value can be used as the namespace part of a ResourceUrl.
@NonNull public java.lang.String getXmlNamespaceUri()
public boolean equals(java.lang.Object o)
equals in class java.lang.Object@NonNull public java.lang.Object readResolve()
public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic int compareTo(@NonNull
ResourceNamespace other)
compareTo in interface java.lang.Comparable<ResourceNamespace>