aboutsummaryrefslogtreecommitdiffstats
path: root/examples/gradle/android.gradle
blob: 4e950d52fcc022cdd96c7840230207dd85073cb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// This Gradle build file illustrates how to process Android
// applications.
// Usage:
//     gradle -b android.gradle proguard
//
// If you're using the Android SDK, the Ant release build and Eclipse export
// already take care of the proper settings. You only need to enable ProGuard
// by commenting in the corresponding line in project.properties. You can still
// add project-specific configuration in proguard-project.txt.
//
// This configuration file is for custom, stand-alone builds.

// Tell Gradle where to find the ProGuard task.

buildscript {
    repositories {
        flatDir dirs: '../../lib'
    }
    dependencies {
        classpath ':proguard'
    }
}

// Define a ProGuard task.

task proguard(type: proguard.gradle.ProGuardTask) {

    // You should probably import a more compact ProGuard-style configuration
    // file for all static settings, but we're specifying them all here, for
    // the sake of the example.
    //configuration 'configuration.pro'

    // Specify the input jars, output jars, and library jars.
    // Note that ProGuard works with Java bytecode (.class),
    // before the dex compiler converts it into Dalvik code (.dex).

    injars  'bin/classes'
    injars  'libs'
    outjars 'bin/classes-processed.jar'

    libraryjars '/usr/local/android-sdk/platforms/android-9/android.jar'
    //libraryjars '/usr/local/android-sdk/add-ons/google_apis-7_r01/libs/maps.jar'
    // ...

    // Save the obfuscation mapping to a file, so you can de-obfuscate any stack
    // traces later on.

    printmapping 'bin/classes-processed.map'

    // You can print out the seeds that are matching the keep options below.

    //printseeds 'bin/classes-processed.seeds'

    // Preverification is irrelevant for the dex compiler and the Dalvik VM.

    dontpreverify

    // Reduce the size of the output some more.

    repackageclasses ''
    allowaccessmodification

    // Switch off some optimizations that trip older versions of the Dalvik VM.

    optimizations '!code/simplification/arithmetic'

    // Keep a fixed source file attribute and all line number tables to get line
    // numbers in the stack traces.
    // You can comment this out if you're not interested in stack traces.

    renamesourcefileattribute 'SourceFile'
    keepattributes 'SourceFile,LineNumberTable'

    // RemoteViews might need annotations.

    keepattributes '*Annotation*'

    // Preserve all fundamental application classes.

    keep 'public class * extends android.app.Activity'
    keep 'public class * extends android.app.Application'
    keep 'public class * extends android.app.Service'
    keep 'public class * extends android.content.BroadcastReceiver'
    keep 'public class * extends android.content.ContentProvider'

    // Preserve all View implementations, their special context constructors, and
    // their setters.

    keep 'public class * extends android.view.View { \
        public <init>(android.content.Context); \
        public <init>(android.content.Context, android.util.AttributeSet); \
        public <init>(android.content.Context, android.util.AttributeSet, int); \
        public void set*(...); \
    }'

    // Preserve all classes that have special context constructors, and the
    // constructors themselves.

    keepclasseswithmembers 'class * { \
        public <init>(android.content.Context, android.util.AttributeSet); \
    }'

    // Preserve all classes that have special context constructors, and the
    // constructors themselves.

    keepclasseswithmembers 'class * { \
        public <init>(android.content.Context, android.util.AttributeSet, int); \
    }'

    // Preserve all possible onClick handlers.

    keepclassmembers 'class * extends android.content.Context { \
       public void *(android.view.View); \
       public void *(android.view.MenuItem); \
    }'

    // Preserve the special fields of all Parcelable implementations.

    keepclassmembers 'class * implements android.os.Parcelable { \
        static android.os.Parcelable$Creator CREATOR; \
    }'

    // Preserve static fields of inner classes of R classes that might be accessed
    // through introspection.

    keepclassmembers 'class **.R$* { \
        public static <fields>; \
    }'

    // Preserve annotated Javascript interface methods.

    keepclassmembers 'class * { \
        @android.webkit.JavascriptInterface <methods>; \
    }'

    // Preserve the required interface from the License Verification Library
    // (but don't nag the developer if the library is not used at all).

    keep 'public interface com.android.vending.licensing.ILicensingService'

    dontnote 'com.android.vending.licensing.ILicensingService'

    // The Android Compatibility library references some classes that may not be
    // present in all versions of the API, but we know that's ok.

    dontwarn 'android.support.**'

    // Preserve all native method names and the names of their classes.

    keepclasseswithmembernames 'class * { \
        native <methods>; \
    }'

    // Preserve the special static methods that are required in all enumeration
    // classes.

    keepclassmembers 'class * extends java.lang.Enum { \
        public static **[] values(); \
        public static ** valueOf(java.lang.String); \
    }'

    // Explicitly preserve all serialization members. The Serializable interface
    // is only a marker interface, so it wouldn't save them.
    // You can comment this out if your application doesn't use serialization.
    // If your code contains serializable classes that have to be backward 
    // compatible, please refer to the manual.

    keepclassmembers 'class * implements java.io.Serializable { \
        static final long serialVersionUID; \
        static final java.io.ObjectStreamField[] serialPersistentFields; \
        private void writeObject(java.io.ObjectOutputStream); \
        private void readObject(java.io.ObjectInputStream); \
        java.lang.Object writeReplace(); \
        java.lang.Object readResolve(); \
    }'

    // Your application may contain more items that need to be preserved; 
    // typically classes that are dynamically created using Class.forName:

    //keep 'public class mypackage.MyClass'
    //keep 'public interface mypackage.MyInterface'
    //keep 'public class * implements mypackage.MyInterface'

    // If you wish, you can let the optimization step remove Android logging
    // calls.
    //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(...);
    //}
}