Using Libraries in Dynamix 1 Plugins

//Using Libraries in Dynamix 1 Plugins
Using Libraries in Dynamix 1 Plugins 2017-09-29T23:38:59+00:00
Special thanks to Lukas Ruge for providing this guide.

Usually it is easy to use .jar files in an android project – just simply drop them into your libs folder and you are done. When writing a Dynamix-Plug-in it’s not that easy. There are several steps you have to follow (the points specific to using libraries are highlighted).

Import the jar

  1. Download the jar from wherever
  2. Drop the .jar into a folder. DO NOT UNDER ANY CIRCUMSTANCES USE THE libs folder, it will now show up as an Android-Dependency AND THIS WILL NOT WORK. I recommend using a folder called lib instead.
  3. And the jar to your build-path manually (right click on the project->build path-> configure build path->add external jar) now it should show up as a Referenced Library.

Create the plug-in

  1. Write your code as usual
  2. Open your MANIFEST.MF and add the jar to your Bundle-ClassPath before the name of the jar you add “.,”. This may for example look like this: Bundle-ClassPath: .,lib/joda-time-2.1.jar (see example under Example Files, note that the SPACE before the . is important.)
  3. Open the build.properties file and add your jar there by changing the second line to bin.includes = META-INF/, ., bin/, assets/,\ and adding a third line lib/joda-time-2.1.jar (see example under Example Files)
  4. Export your plug-in as usual

Note: If you are using the DynmixPluginBuilder you cannot use libraries. If you need a library you have to use Eclipse, going export->Deployable plug-ins and fragments and then copy the classes.dex file in the resulting jar from the bin to the root folder.

Dexing the library

  1. Copy the library .jar (for example joda-time-2.1.jar) into the android-sdk-windows\build-tools\<sdk-number>
  2. Open the windows console/terminal
  3. Navigate to your build-tools\<sdk-number> -folder in the android-sdk folder
  4. Use the dx command to dex the library. For example:
  5. delete the old jar and rename the new one to have the same name as the old oneReplace the Library
  6. open your plug-in jar-file and replace the library .jar in the library subfolder with the new, dexed, library (you have to do this after every export, or you just place the dexed library in your project)
Note: You only have to do this once!

Upload your plug-in

  1. Create the XML-File to add your plug-in to the plug-in-repository (if you don’t change much on the plug-in you do not need to change the XML most of the times…)
  2. Upload the xml file and the plug-in .jar
  3. Test your plug-in
  4. Find your plug-in in Dynamix and install it, test if it works

Note: Plug-ins only run if there is a context subscription to them so you have to write an app to subscribe to your context type if there isn’t an app for that yet.

Errors you might see

Dynamix just tells you that there was an error message using TOAST. You have to use DDMX in Eclipse to see what error it was, there are two likely errors:

  • java.lang.NoClassDefFoundError:
    • The library hasn’t been exported at all. This may, for example, be because of a spelling error in one of the files, or maybe you did not use –keep-classes while dexing.
    • Another possibility is that you are using the DynamixPluginBuilder
  • java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation:
    • It found the library, but the class definitions were different than expected, or there were multiple identical classes. This most likely happened because you used the libs-folder for your jar file. What to do if this happens? Sadly right now Dynamix doesn’t cope well with these errors and simply uninstalling the old plug-in and installing a (hopefully) fixed version will not work. I found it necessary to uninstall the plug-in, stop Dynamix, restart the phone, and start Dynamix up again. Install your plug-in before you start the subscribing app, watch Dynamix install but not start the plug-in. Then start the app and watch DDMX to see if it works.

Example files

MANIFEST.MF

build.properties