In previous releases, the native Android resources in the
Android Native Extension could only be accessed by using the
getResourceID()
API
while the R.* mechanism could not be used with the ANEs. Beginning
AIR 4.0, you can access resources with the R.* mechanism. When using
the R.* mechanism, ensure that you use the platform descriptor,
platform.xml, which has all the dependencies defined:
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://ns.adobe.com/air/extension/4.0"
xmlns="http://ns.adobe.com/air/extension/4.0"
elementFormDefault="qualified">
<xs:element name="platform">
<xs:complexType>
<xs:all>
<xs:element name="description" type="LocalizableType" minOccurs="0"/>
<xs:element name="copyright" type="xs:string" minOccurs="0"/>
<xs:element name="packagedDependencies" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="packagedDependency" type="name" minOccurs="0" maxOccurs="unbounded"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="packagedResources" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="packagedResource" minOccurs="0" maxOccurs="unbounded"/>
<xs:complexType>
<xs:all>
<xs:element name="packageName" type="name" minOccurs="0"/>
<xs:element name="folderName" type="name" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:all>
</xs:element>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:simpleType name="name">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9\-\.]{1,255}"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="LocalizableType" mixed="true">
<xs:sequence>
<xs:element name="text" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="lang" type="xs:language" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Following is an example of the dependencies in
platform.xml
:
<packagedDependencies>
<packagedDependency>android-support-v4.jar</packagedDependency>
<packagedDependency>google-play-services.jar</packagedDependency>
</packagedDependencies>
<packagedResources>
<packagedResource>
<packageName>com.myane.sampleasextension</packageName>
<folderName>ane-res</folderName>
</packagedResource>
<packagedResource>
<packageName>com.google.android.gms</packageName>
<folderName>google-play-services-res</folderName>
</packagedResource>
</packagedResources>
where:
-
packagedDependencies
is used to provide
the name of all the jars on which the ANE is dependent.
-
packagedResources
defines the resources
used by the ANE or any other jar file.
-
folderName
defines the name of the resources
folder.
-
packageName
defines the package name of
the jar that uses the resources.
-
packagedDependencies
and
packagedResources
will
be available from extension namespace 4.0 onwards.
The Android-ARM folder contains all the ANE jar files and resources
as well as the third-party jar files. Following is a sample ANE
packaging command:
bin/adt -package -target ane sample.ane extension.xml -swc sampleane.swc -platform Android-ARM -platformoptions platform.xml -C Android-ARM .
You do not need to merge the third-party jar files and resources
with the ANE jar and resources when using the R.* resource access
mechanism. ADT merges the jars and resources internally. All dependencies
and resources still need to be packaged in the ANE.
Note that:
-
An ANE project should be a library project for the R.*
resource access mechanism to work.
-
There is no restriction on the name of the resource folder,
it can either start with 'res' or any other valid string.
-
If the
-platformoptions
switch is not used
while packaging an ANE, resource access is only possible via the
getResourceId()
mechanism.