如何配置ProGuard的仅删除记录的Andr​​oid电话电话、ProGuard、Andr、oid

2023-09-04 06:31:53 作者:捧一束彼岸花

我想配置ProGuard的只调用android.util.Log从我的Andr​​oid应用程序中删除(对于发行版本)。我特别不希望的ProGuard做的code任何混淆或缩小。

这是我试过的配置,但它不会删除登录电话(我假设,因为 -keep类**

  -optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dont preverify
-verbose
-optimizations!code /简/算术,!现场/ * ,!类/合并/ *

-keepattributes Exceptions,InnerClasses,Signature,De$p$pcated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-keep类** {
    *;
}

-assumenosideeffects类android.util.Log {
    *;
}
 

是我在问什么甚至有可能使用ProGuard?

ProGuard的-project.txt此选项解决方案

您可以删除通话记录

  -assumenosideeffects类android.util.Log {
    公共静态布尔isLoggable(java.lang.String中,INT);
    公共静态INT V(...);
    公共静态INT I(...);
    公共静态INT W(...);
    公共静态INT D(...);
    公共静态INT E(...);
}
 

如果优化未禁用,像此选项仅与ProGuard的-android.txt 。你必须指定 ProGuard的-Android的optimize.txt 相反, project.properties

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

您可以禁用收缩和模糊处理,如果你的愿望。您也可以preserve从优化应用程序的内部API,如果你想:

  -keep类的myapp ** {*。 }
 

禁用这些步骤,并保持当然,所有code不是从一个ProGuard的角度最佳的。

I'm trying to configure proguard to ONLY remove calls to android.util.Log from my Android app (for the release build). I specifically don't want proguard to do any obfuscation or minification of the code.

This is the configuration I've tried but it doesn't remove the Log calls (I assume because of the -keep class **)

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-keep class ** {
    *;
}

-assumenosideeffects class android.util.Log {
    *;
}

Is what I'm asking even possible with proguard?

解决方案

You can remove logging calls with this option in proguard-project.txt:

-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(...);
}

This option is only relevant if optimization is not disabled, like in proguard-android.txt. You have to specify proguard-android-optimize.txt instead, in project.properties:

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

You can disable shrinking and obfuscation if you wish. You can also preserve the internal API of your application from optimization if you wish:

-keep class myapp.** { *; }

Disabling these steps and keeping all code of course isn't optimal from a ProGuard point of view.