1// 2// This Gradle build file illustrates how to process Android 3// applications. 4// Usage: 5// gradle -b android.gradle proguard 6// 7// If you're using the Android SDK, the Ant release build and Eclipse export 8// already take care of the proper settings. You only need to enable ProGuard 9// by commenting in the corresponding line in project.properties. You can still 10// add project-specific configuration in proguard-project.txt. 11// 12// This configuration file is for custom, stand-alone builds. 13 14// Tell Gradle where to find the ProGuard task. 15 16buildscript { 17 repositories { 18 flatDir dirs: '../../lib' 19 } 20 dependencies { 21 classpath ':proguard' 22 } 23} 24 25// Define a ProGuard task. 26 27task proguard(type: proguard.gradle.ProGuardTask) { 28 29 // You should probably import a more compact ProGuard-style configuration 30 // file for all static settings, but we're specifying them all here, for 31 // the sake of the example. 32 //configuration 'configuration.pro' 33 34 // Specify the input jars, output jars, and library jars. 35 // Note that ProGuard works with Java bytecode (.class), 36 // before the dex compiler converts it into Dalvik code (.dex). 37 38 injars 'bin/classes' 39 injars 'libs' 40 outjars 'bin/classes-processed.jar' 41 42 libraryjars '/usr/local/android-sdk/platforms/android-9/android.jar' 43 //libraryjars '/usr/local/android-sdk/add-ons/google_apis-7_r01/libs/maps.jar' 44 // ... 45 46 // Save the obfuscation mapping to a file, so you can de-obfuscate any stack 47 // traces later on. 48 49 printmapping 'bin/classes-processed.map' 50 51 // You can print out the seeds that are matching the keep options below. 52 53 //printseeds 'bin/classes-processed.seeds' 54 55 // Preverification is irrelevant for the dex compiler and the Dalvik VM. 56 57 dontpreverify 58 59 // Reduce the size of the output some more. 60 61 repackageclasses '' 62 allowaccessmodification 63 64 // Switch off some optimizations that trip older versions of the Dalvik VM. 65 66 optimizations '!code/simplification/arithmetic' 67 68 // Keep a fixed source file attribute and all line number tables to get line 69 // numbers in the stack traces. 70 // You can comment this out if you're not interested in stack traces. 71 72 renamesourcefileattribute 'SourceFile' 73 keepattributes 'SourceFile,LineNumberTable' 74 75 // RemoteViews might need annotations. 76 77 keepattributes '*Annotation*' 78 79 // Preserve all fundamental application classes. 80 81 keep 'public class * extends android.app.Activity' 82 keep 'public class * extends android.app.Application' 83 keep 'public class * extends android.app.Service' 84 keep 'public class * extends android.content.BroadcastReceiver' 85 keep 'public class * extends android.content.ContentProvider' 86 87 // Preserve all View implementations, their special context constructors, and 88 // their setters. 89 90 keep 'public class * extends android.view.View { \ 91 public <init>(android.content.Context); \ 92 public <init>(android.content.Context, android.util.AttributeSet); \ 93 public <init>(android.content.Context, android.util.AttributeSet, int); \ 94 public void set*(...); \ 95 }' 96 97 // Preserve all classes that have special context constructors, and the 98 // constructors themselves. 99 100 keepclasseswithmembers 'class * { \ 101 public <init>(android.content.Context, android.util.AttributeSet); \ 102 }' 103 104 // Preserve all classes that have special context constructors, and the 105 // constructors themselves. 106 107 keepclasseswithmembers 'class * { \ 108 public <init>(android.content.Context, android.util.AttributeSet, int); \ 109 }' 110 111 // Preserve all possible onClick handlers. 112 113 keepclassmembers 'class * extends android.content.Context { \ 114 public void *(android.view.View); \ 115 public void *(android.view.MenuItem); \ 116 }' 117 118 // Preserve the special fields of all Parcelable implementations. 119 120 keepclassmembers 'class * implements android.os.Parcelable { \ 121 static android.os.Parcelable$Creator CREATOR; \ 122 }' 123 124 // Preserve static fields of inner classes of R classes that might be accessed 125 // through introspection. 126 127 keepclassmembers 'class **.R$* { \ 128 public static <fields>; \ 129 }' 130 131 // Preserve annotated Javascript interface methods. 132 133 keepclassmembers 'class * { \ 134 @android.webkit.JavascriptInterface <methods>; \ 135 }' 136 137 // Preserve the required interface from the License Verification Library 138 // (but don't nag the developer if the library is not used at all). 139 140 keep 'public interface com.android.vending.licensing.ILicensingService' 141 142 dontnote 'com.android.vending.licensing.ILicensingService' 143 144 // The Android Compatibility library references some classes that may not be 145 // present in all versions of the API, but we know that's ok. 146 147 dontwarn 'android.support.**' 148 149 // Preserve all native method names and the names of their classes. 150 151 keepclasseswithmembernames includedescriptorclasses:true, 'class * { \ 152 native <methods>; \ 153 }' 154 155 // Preserve the special static methods that are required in all enumeration 156 // classes. 157 158 keepclassmembers allowshrinking:true, 'enum * { \ 159 public static **[] values(); \ 160 public static ** valueOf(java.lang.String); \ 161 }' 162 163 // Explicitly preserve all serialization members. The Serializable interface 164 // is only a marker interface, so it wouldn't save them. 165 // You can comment this out if your application doesn't use serialization. 166 // If your code contains serializable classes that have to be backward 167 // compatible, please refer to the manual. 168 169 keepclassmembers 'class * implements java.io.Serializable { \ 170 static final long serialVersionUID; \ 171 static final java.io.ObjectStreamField[] serialPersistentFields; \ 172 private void writeObject(java.io.ObjectOutputStream); \ 173 private void readObject(java.io.ObjectInputStream); \ 174 java.lang.Object writeReplace(); \ 175 java.lang.Object readResolve(); \ 176 }' 177 178 // Your application may contain more items that need to be preserved; 179 // typically classes that are dynamically created using Class.forName: 180 181 //keep 'public class mypackage.MyClass' 182 //keep 'public interface mypackage.MyInterface' 183 //keep 'public class * implements mypackage.MyInterface' 184 185 // If you wish, you can let the optimization step remove Android logging 186 // calls. 187 //assumenosideeffects class android.util.Log { 188 // public static boolean isLoggable(java.lang.String, int); 189 // public static int v(...); 190 // public static int i(...); 191 // public static int w(...); 192 // public static int d(...); 193 // public static int e(...); 194 //} 195} 196