androidapache-flexairair-native-extensionaapt

Adobe Native Extensions: How do I package third party libraries (.jar) in a Android Native Extension for my Flex App?


This is not a duplicate question, I will post the links to the questions whose 'accepted' answers did not work for me.

I have been trying to integrate a third party library for my flex android application for a few weeks now, with no success. Unfortunately there is no reliable end-to-end documentation for the same. What little Adobe has documented on the topic is insufficient to say the least.

The tools I am using:

  1. ADT to package ANE from command line on Windows 7.
  2. Flash Builder to package the final APK (ANE with the flash part)

My directory structure for the ANE:

enter image description here

The ADT command I am using:

<Adt path>\adt -package -storetype PKCS12 -keystore ./cert.p12 -storepass <password> -target ane myane.ane ./build/ane/extension.xml -swc ./build/ane/*.swc -platform Android-ARM -platformoptions platform.xml -C ./build/ane/Android-ARM/ . -platform Android-x86 \ -C ./build/ane/Android-ARM/ .

Here are a few questions on Stack Overflow that I did refer to and which did not work for me:

Question#1: Accepted answer is to simply combine both JAR files using the JAR tool in java. It did not work for me, I get a NoClassDefFound error when trying to access any class inside ThirdPartyJar.jar. I export my Native Jar from Eclipse like this:

enter image description here

enter image description here

My doubt here is, in combining the two JARs where did I define the dependency? How is a simple combination of JARs working for others who have accepted the answer?

Question#2 : The accepted answer here talks about creating a platform options XML which defines the said 'packaged dependency'. Seems more logical. I tried to create it, as visible in my folder structure above and the adt command I am using. Here's how the 'platform.xml' looks:

<platform xmlns="http://ns.adobe.com/air/extension/4.0">
    <packagedDependencies>
        <packagedDependency>ThirdPartyJar.jar</packagedDependency>
    </packagedDependencies>
    <packagedResources>
    </packagedResources>
</platform>

At first, I was getting an 'Namespace should be same as extension.xml' error while trying to build the ANE, but after I changed both of them to '...../4.0' I could build the ANE without any errors. However, when I included the ANE in my Flex Project, and tried to Run As > Mobile Application, it would give me this error:

enter image description here

I would then rename the strings.xml file in my Android Native Project, re-build the ANE, to get this error:

enter image description here

How do I get it to work? Between these two solutions I have tried myriad ways to package the two JARs together but it just would not work!


Solution

  • Your second method using the platform options method is the best method available.

    Problem with packaged dependencies with Android and AIR are nearly always caused by the build tools in the AIR SDK. The versions included with older versions of the SDK are not recent enough to use the latest features from the Google Play Library nor use some of the more recent SDK's.

    If you have the Android SDK build tools installed then you can copy the dx.jar file from build-tools/x.x.x/lib/dx.jar over the same file in your AIR SDK located here:

    AIRSDK/lib/android/bin/dx.jar
    

    You must replace the one in the AIR SDK with the one from the Android build tools and not the other way around.

    I also highly suggest you update adb at this time. Updating adb can solve a lot of connection and debugging issues.

    You should not use a version > 20.0 of the Android build tools. Anything higher than 20.0 currently has issues with the AIR packager.

    If you use AIR 18+ the build tools have been updated to v20.0.0 and you shouldn't have to update the build tools unless you are using even more modern features (such as the android support v13 lib).

    Reference: http://airnativeextensions.com/knowledgebase/tutorial/5