user45678
user45678

Reputation: 1514

Where to add Proguard Custom Rules?

I am trying to add custom Proguard rules for my app, but I am not sure into which file I should add those custom rules. I know of three files

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

Upvotes: 2

Views: 2186

Answers (2)

Free Palestine
Free Palestine

Reputation: 1184

First of all you will use the

3)Project --> app --> proguard-rules.pro

and

few generic custom rules which are safe to apply on app and wouldn't hinder the functioning of it

depends on the code in your app but if you will set minifyEnabled to true(which is recommended) this could lead to a lot of issues which can be solved through proguard rules file.

This is my proguard file for one of my projects where I'm using Fabric, httpApacheClient, shareActionProvider and some other libraries that needs specific rules for 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

And almost you will find related proguard settings in the documentation of any external library you use.

Upvotes: 2

Abhishek Bansal
Abhishek Bansal

Reputation: 5345

in

3)Project --> app --> proguard-rules.pro

There are not generic proguard rules. All those generic ones already included with SDK, It depends on what features and libraries are you using in your project. Also there is no safeway of doing it. You have to apply rules and test app -> fix any issues then repeat same process.

Upvotes: 1

Related Questions