Search code examples
androidxmlporting

How to back port Android 2.2 XML features to Android 1.5?


I have an app written for Android 2.2 (API 8) that depends on some XML features that were introduced in that API version, for example TransformerFactory.

Now I need to make the app work on an Android 1.5 device. I was wondering if it's possible to get the source code or JAR file that contains this code and insert it into my app? I'm assuming it doesn't have any external dependencies on Android 2.2 features since it is just an XML library.


Solution

  • I discovered it is not really possible to extract the parts I needed from the Android source. There were dependencies on Dalvik internals.

    However, I found another question that helped me solve my real need: some way to write a DOM tree to an XML file prior to Android 2.2: Writing XML on Android

    The solution I took was to write a class that recurses over a DOM tree and writes the nodes using the org.xmlpull.v1.XmlSerializer class (which you can get an instance of via android.util.Xml.newSerializer())

    Then I used a lazy-loading technique to make my application load my custom class if the Android SDK was less than API 8 (Android 2.2). Otherwise it would use a wrapper class for the standard Transformer class. See: How to have your cupcake and eat it too