Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What optimisation is safe that still allows -assumenosideeffects removals

I've noticed that with projects I have created recently, there comes a new approach to proguard which is to use a pre-built script:

${sdk.dir}/tools/proguard/proguard-android.txt

This is without optimisation, and comes with a comment:

Optimization is turned off by default. Dex does not like code run through the ProGuard optimize and preverify steps (and performs some of these optimizations on its own).

It appears that following this advice means that assumenosideeffects has no effect. For example, these common tasks:

#Remove logging
-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

#Remove asserts
-assumenosideeffects class junit.framework.Assert {
  public static *** assert*(...);
}

Proof it's not working:

if (release)
{
    Assert.assertTrue("Proguard config error, Asserts have been left in", false);
}

Is there a safe middle ground, where I can apply optimisation to trim out debug as defined with assumenosideeffects, but without risking the associated problems with Dex and proguard optimisation?

like image 992
weston Avatar asked Jun 08 '13 12:06

weston


1 Answers

The solution that I have found is to explicitly only enable the optimizations that the assumenosideeffects command depends on. So an example proguard config would be the following:

# proguard-project.txt

# Remove all Verbose/Debug logging
-optimizations code/removal/simple,code/removal/advanced
-dontobfuscate
-assumenosideeffects class android.util.Log {
    public static int v(...);
    public static int d(...);
}

Note that the project.properties file should specify the optimize SDK proguard config file, since a single call to -dontoptimize disables optimizations.

# project.properties

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
like image 119
Andrey Avatar answered Oct 30 '22 13:10

Andrey