15
I’m not getting Proguard 4.10 to make a method static
turn inline. I can only do that with instance methods.
For example, this little bit:
public final class Calc {
private int x = 0;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
Calc c = new Calc();
int res = c.getX();
if ((c.getX() & 1) != 0)
res++;
else
res += 2;
c.setX(res);
System.out.println(res);
}
}
Once processed by Proguard transforms into (disregarding obfuscation):
public final class Calc {
private int x = 0;
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
Calc c = new Calc();
int res = c.x;
if ((c.x & 1) != 0)
res++;
else
res += 2;
c.x = res;
System.out.println(res);
}
}
However, I adapt the classes, and transform the methods into static
, that stretch below does not change (disregarding the obfuscation):
public final class Calc {
private static int x = 0;
public static int getX() {
return x;
}
public static void setX(int x) {
Calc.x = x;
}
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
int res = Calc.getX();
if ((Calc.getX() & 1) != 0)
res++;
else
res += 2;
Calc.setX(res);
System.out.println(res);
}
}
To answer any questions, here is the configuration I am using in both cases:
-dontskipnonpubliclibraryclassmembers
-optimizationpasses 9
-allowaccessmodification
-mergeinterfacesaggressively
-dontusemixedcaseclassnames
-dontpreverify
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
-keep class * extends java.sql.Driver
-keep class * extends javax.swing.plaf.ComponentUI {
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent);
}
-keepclasseswithmembers,allowshrinking class * {
native <methods>;
}
Am I missing something? There is no option to make Proguard optimize and make methods static
inline?
Already these three documentations (besides many others) and I found nothing mentioning this case. It would be a limitation of Proguard?
I don’t know if you’ve solved it yet, but see if it helps you:

 http://stackoverflow.com/questions/18452928/remove-unused-classes-with-proguard-for-android
– Alberto Lourenço
@Albertolourenço Valeu, but it’s not quite that yet :( I need to make a method
static
of a class be replaced by its content. But, thanks! :)– carlosrafaelgn