2

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!

Community
  • 1
  • 1
devanshu_kaushik
  • 929
  • 11
  • 30
  • IRT "Question 1 didn't work" - if you unzip the resulting .jar, do you see the .class files you expect from your thirdPartyJar? – Brian Sep 25 '15 at 16:40
  • Yes, they are present . – devanshu_kaushik Sep 25 '15 at 16:43
  • Can you share what the third-party library is? Also, if you put in logging in your own code, do you see the logging before the NoClassDefFound error? From your screenshot, it looks like you're packaging .java files rather than .class files when you export your .jar (that's probably not the issue, but it's worth checking). – Brian Sep 25 '15 at 16:43
  • Yes, I do see the logs before. The third party library is Brightcove (a video player). Those are .class files. My AndroidNativeJar.jar contains .java files, but that part ran as expected when integrated without the code from Brightcove. After integration, I get a NPE when I try to reference any Brightcove class. – devanshu_kaushik Sep 25 '15 at 17:30
  • If you unzip your .ane file, do you see the Brightcove .class files? – Brian Sep 25 '15 at 18:21
  • What version of AIR are you using? My guess would be an old version of aapt is causing your second issue. – Michael Sep 27 '15 at 23:06
  • @Brian - When I unzip my .ane file, I see the Brightcove class files inside the combined .jar file as before, along with .class files from my native android code. Am I supposed to see it outside the .jar? – devanshu_kaushik Sep 28 '15 at 06:08
  • @Michael I am using 4.6.0-AIR 15.0 . I was not getting any aapt errors before using '-platformoptions' while packaging the .ane – devanshu_kaushik Sep 28 '15 at 06:53
  • @dev_android That's what I expected to see. The Brightcove classes don't involve Java Annotations, do they? – Brian Sep 28 '15 at 14:56
  • @Brian No. I found the cause finally. I needed to upgrade dx.jar inside the flex SDK. Seems like the difference in java versions of the tool and library was the reason for the exclusion. Thanks for replying though! – devanshu_kaushik Sep 28 '15 at 15:01
  • Yeah, if you use 18 + it should have the updated dx.jar for you, hence the reason I asked about the AIR version. – Michael Sep 29 '15 at 01:50

1 Answers1

2

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

Michael
  • 3,776
  • 1
  • 16
  • 27
  • Also, please vote for this bug to get the aapt version updated: https://bugbase.adobe.com/index.cfm?event=bug&id=4057897 – Michael Sep 29 '15 at 01:59
  • Do you know how to export a similar JAR file (with dependencies) in Android Studio -- for the same purpose, that is, to use it in a native extension? – devanshu_kaushik Dec 29 '15 at 07:41