在哪里添加Proguard自定义规则?

时间:2017-03-21 06:28:48

标签: android

我正在尝试为我的应用添加自定义Proguard规则,但我不确定在哪个文件中我应该添加这些自定义规则。我知道三个文件

1)Android/sdk/tools/proguard/proguard-android.txt
2)Android/sdk/tools/proguard/proguard-project.txt
3)Project --> app --> proguard-rules.pro

2 个答案:

答案 0 :(得分:2)

首先,您将使用

  

3)项目 - > app - > proguard-rules.pro

  

一些通用的自定义规则,可以安全地应用于应用程序而不会   阻碍它的运作

取决于您应用中的代码,但如果您将minifyEnabled设置为true(建议使用),则可能会导致许多问题可以通过proguard规则文件解决。

这是我的一个项目的proguard文件,我正在使用Fabric,httpApacheClient,shareActionProvider和其他一些需要针对proguard的特定规则的库。

 # This will ignore warnings for missing translations and some other wanrinings 
-ignorewarnings

# Keeping line numbers for easy error tracking :

-keepattributes SourceFile,LineNumberTable

# Support ShareActionProvider  will not work without this line :
-keep class android.support.v7.widget.ShareActionProvider { *; }

# Flurry Crashlytics

-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int); }

# Preserve Flurry mediation classes for DFP/AdMob Ads ­keep public class com.google.ads.mediation.flurry.**

# Google Play Services library
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents(); }

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL; }
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *; }
-keepnames class * implements android.os.Parcelable { public static final ** CREATOR;
}

-keepattributes InnerClasses, EnclosingMethod
-keep class com.ironsource.mobilcore.**{ *; }
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn android.app.Notification

-keep   class   com.dianxinos.DXStatService.stat.TokenManager   {
public  static  java.lang.String getToken(android.content.Context);
}

-keep   public  class   *   extends android.content.BroadcastReceiver
-keep   public  class   *   extends android.app.Activity
-keep   public  class   *   extends android.content.ContentProvider

几乎你会在你使用的任何外部库的文档中找到相关的proguard设置。

答案 1 :(得分:1)

in

  

3)项目 - &gt; app - &gt; proguard-rules.pro

没有通用的proguard规则。所有那些通用的已包含在SDK中,这取决于您在项目中使用的功能和库。此外,没有safe方式。您必须应用规则和测试应用 - &gt;修复任何问题然后重复相同的过程。

相关问题