AIR 4.0 and later supports packaging of multiple JAR files in an ANE. That allows packaging of third party libraries and their corresponding resources an ANE.
The resources bundled in an ANE or any other library in the ANE can be accessed by R* method, and this document provides all the details.
This post talks about a scenario where multiple ANEs are used in an app and if two or more of the ANEs use same JAR file as a dependency (packagedDependency). It is not possible to create such an app, and the packager fails with following error –
unexpected failure: duplicate entry: /R.class
This is expected because when the packager picks up resources of all the ANEs, and finds that two or more ANEs are using a same resource, the step to convert *.java to *.class file fails with a duplicate entry error. This is something which the packager cannot resolve by itself, and the developer has to step in.
If you face this packaging error, you need to remove the common JAR from all of the ANEs but one, to ensure that the packager finds a single copy of every JAR file as input.
Here is an example –
Suppose there are two ANEs used in an app i.e. example1.ane and example2.ane. Both of them use a common library, say commonlibrary.jar, and its resources, say, common-lib-res. If you try to package the app with these ANEs, ADT throws an error –
unexpected failure: duplicate entry: com.common.example.lib/R.class
To resolve the issue, you need to follow these steps (eg. is for a Mac) –
1. Copy example1.ane in a temp folder.
2. Unzip example.ane (run command ‘unzip example1.ane‘)
3. Remove the commonlibrary.jar from the package (i.e. from unzipped content of the ANE).
4. Remove the corresponding resources of commonlibrary.jar (i.e. “common-lib-res“) from the package.
5. In platform.xml, delete the entry for commonlibrary.jar from the tag and delete the entry of the common-lib-res from the tag.
6. Zip back contents of package to ANE –
- zip –r –D example1.zip META-INF catalog.xml library.swf mimetype
- rm –rf example1.ane META-INF catalog.xml library.swf mimetype
- mv example1.zip example1.ane
Use this new temp/example1.ane and existing example2.ane to package the APK file. You should not see any packaging or runtime error now.
Hope that helps!