1

I'm only using Proguard (version 5.2.1) to shrink, not to obfuscate or optimize. Here's my config:

-forceprocessing
-dontobfuscate
-dontoptimize
-dontwarn
-dontnote
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers

-libraryjars <java.home>/lib

-keep class ** extends **.MyRequestHandler
-keep @org.springframework.stereotype.Component class **
-keep @org.aspectj.lang.annotation.Aspect class **
-keep @interface *

I have a class which is an AspectJ aspect that looks like this:

@Aspect
public class MyAspect {

    @Pointcut("execution(* com.amazonaws.services.dynamodb*.*AmazonDynamoDB.*(..))") 
    public void myPointCut() {
    }

    @Around(value = "myPointCut()")
    public Object logExecution(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println(joinPoint);
        return joinPoint.proceed();
    }

}

When I feed my application through Proguard, and then decompile the resulting class file, this is what it looks like:

@Aspect
public class MyAspect {

    @Pointcut("execution(* com.amazonaws.services.dynamodb*.*AmazonDynamoDB.*(..))") 
    public void myPointCut() {
    }

    @Around
    public Object logExecution(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println(joinPoint);
        return joinPoint.proceed();
    }

}

Notice that the "value" parameter from the @Around annotation is missing! This is very weird behavior... I almost think it's a bug in Proguard. It's keeping the annotation itself, just not the parameter... though weirdly enough it is keeping the parameter from the @Pointcut annotation. Does anyone know how to fix this?

As a reminder, I'm only shrinking, and the -keepattributes config is only for obfuscation, so please no one respond that -keepattributes *Annotation* will fix it. I've tried it and it has no effect.

I found this similar question (annotations having no effect in proguard) which is where I got the -keep @interface * config. This setting is supposed to keep all annotations, which it seems to be doing, but for some reason it's not keeping all of the parameters. I tried many variations of this, such as:

  1. -keep @interface **
  2. -keep @interface* *
  3. -keep @interface.On *
  4. -keep @interface.* *
  5. -keepclassmembers class ** { @org.aspectj.lang.annotation.Around ; }
  6. -keepclassmembers class ** { @org.aspectj.lang.annotation.Around.On ; }
  7. -keepclassmembers class ** { @org.aspectj.lang.annotation.Around.* ; }

Some of these approaches just cause Proguard to throw an error, and the ones that don't aren't having any effect. Please help!

Dasmowenator
  • 5,505
  • 5
  • 36
  • 50

1 Answers1

1

The answer was posted on this ProGuard bug report: https://sourceforge.net/p/proguard/bugs/700/

You just need to change this config value:

-keep @interface *

To this:

-keep @interface * {*;}

This still seems like a bug in ProGuard because I'm clearly using those annotation parameters, and I'm telling ProGuard to keep the classes and the annotations, so it shouldn't be removing them... but this is the workaround.

Dasmowenator
  • 5,505
  • 5
  • 36
  • 50