I have a issue that Proguard is not working when you declare a anonymous class within a anonymous class. This is what it looks like in a basic example:
public class Class1 {
public void function1 (){
new Class2(){
@Override
public void function2(){
new Class3(){
@Override
public void function3(){
// do something
}
}
}
}
}
}
During a gradle build script proguard is being executed. Now i get the following error:
my.package.Class1$2$1: can't find enclosing method 'void function2()' in program class my.package.Class1$2
If I change the code to just have 1 "level" of anonymous classes proguard is finishing without errors. This works:
public class Class1 {
public void function1 (){
Class3 class3Instance = new Class3(){
@Override
public void function3(){
// do something
}
}
new Class2(){
@Override
public void function2(){
//do something with class3Instance
}
}
}
}
The project is a android project, though as far as I know that should not matter.
I tried all different kind of -keep
rules for Class1
, but nothing worked. Is this not supported by Proguard or do I have to add a rule to get it to work?
UPDATE 1:
As requested the structure if the interface used for the anonymous classes.
The interface for Class2
is defined as follows:
public class Class2IntefaceEnclosingClass {
public interface Class2 {
void function2();
}
}
The interface for Class3
is slightly different:
public interface Class3IntefaceEnclosingInterface {
interface Class3 {
void function3();
}
}
Note: I can not change the layout of the interfaces since they are provided by android.