Question

I have a project set up in Android Studio that is relying on a jar file that is imported from a remote repository by Gradle. This means no "/libs" folder.

This jar file contains a bunch of JAXB objects with xml annotations that look like this:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Accounts", propOrder = {
    "account"
})

However, on the Android side, I am using Gson to serialize these objects. I didn't think these annotations would be a problem, but Gson is detecting them via reflection. I would like to remove them using ProGuard, but have no idea where to start, or if it's even possible.

I think I want to use the -libraryjars flag in my configuration file, but don't know how to get a dynamic path to a jar file imported by Gradle. The documentation for using ProGuard for Android hasn't been very helpful so far.

Was it helpful?

Solution

The Android documentation explains how to enable ProGuard in your builds (Ant, Eclipse, or Gradle). Once it is enabled:

  1. ProGuard's shrinking step removes annotations if they appear to be unused in the code. If Gson uses the annotations, they probably won't be removed.

  2. ProGuard's obfuscation step removes all annotations by default, unless the configuration specifies:

    -keepattributes *Annotation*
    

    The global configuration file in the Android SDK, android-sdk/tools/proguard/proguard-android.txt, contains this line, because most developers want to preserve annotations. If you comment it out, all annotations will be removed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top