Search code examples
javaandroidpackagerome

Changing classes' canonical names in package


A bit of background (not directly relevant as my question is quite general): I want to use Android ROME Feed Reader library to parse RSS feed that has media content. But ROME doesn't support media out of the box, so I want to make use of a media plugin which comes as a separate JAR and builds upon the original library.

So I have two JARs (for which I have no source code), and my gradle dependencies look like this:

dependencies {
  compile files('libs/android-rome-feed-reader-1.0.0.jar')
  compile files('libs/mediarss-0.2.3.jar')
}

The problem is that the package names from the Android version of ROME are all prefixed with com.google.code.rome.android.repackaged. with respect to the original library.

For instance, Android ROME lib contains the following interface:

package com.google.code.rome.android.repackaged.com.sun.syndication.feed.module;
public interface Module { /* ... */ }

While all the classes in the media plugin refer to the original canonical names:

public interface MediaModule extends com.sun.syndication.feed.module.Module { /* ... */ }

Quite naturally, compilation fails:

Error:(69, 34) error: cannot access Module
class file for com.sun.syndication.feed.module.Module not found

Is there a workaround for this? Can I somehow statically change the canonical names for all classes in the library? Or is there some other solution?

Thanks!


Solution

  • Ha, thats a silly issue. Seen stuff like this before. Your easiest bet is this: Jar Jar Links.

    Simple:

    • Make a rules.txt in the same directory as jarjar.jar with the following:
    • rule com.google.rome.** com.foo.bar.@1
    • cd to te directory of jarjar.jar
    • run java -jar jarjar.jar rules.txt ~/path_to/old_jar ~/path_to/new_jar

    Should repackage everything for ya to not be silly.