Which optimization is safe, which still allows -use absorption

I noticed that with newly created projects, a new approach to proguard has appeared, which should use a pre-built script:

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

This is without optimization and comes with a comment:

Optimization is disabled by default. Dex does not like running code through ProGuard to optimize and pre-check steps (and performs some of these optimizations separately).

It seems that following this advice means that assumenosideeffects not valid. 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 that it does not work:

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

Is there a safe middle ground where I can apply optimization to trim debugging, as defined in assumenosideeffects , but without risking the associated problems with optimizing Dex and proguard?

+6
source share
1 answer

The solution I found should explicitly include only the optimization on which the assumenosideeffects command assumenosideeffects . Thus, a proguard configuration example would be as follows:

 # 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 must specify the configuration file to optimize the proguard SDK, since a single call to -dontoptimize disables optimization.

 # project.properties proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt 
+1
source

Source: https://habr.com/ru/post/946849/


All Articles