Skip to content

Commit 1b44559

Browse files
Update manual
1 parent aa1835f commit 1b44559

36 files changed

+1393
-28
lines changed

docs/md/manual/FAQ.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Yes, you can. **ProGuard** itself is distributed under the GPL, but this
6868
doesn't affect the programs that you process. Your code remains yours, and its
6969
license can remain the same.
7070

71-
## Does ProGuard work with Java 2, 5,..., 15? {: #jdk1.4}
71+
## Does ProGuard work with Java 2, 5,..., 19? {: #jdk1.4}
7272

7373
Yes, **ProGuard** supports all JDKs from 1.1 up to and including 19. Java 2
7474
introduced some small differences in the class file format. Java 5 added
@@ -90,19 +90,12 @@ preverifier.
9090

9191
## Does ProGuard Support Android Apps?
9292

93-
ProGuard no longer supports Android apps, and for shrinking & optimization
94-
we recommend using the default shrinker R8.
95-
R8 is distributed as part of the Android SDK, it's fast, and can shrink & optimize apps well.
93+
The **ProGuard Gradle Plugin** is compatible with Android Gradle Plugin (AGP) versions 4.x - 7.x.
9694

97-
However, R8 is only a shrinker & optimizer and does not provide any security features.
98-
To protect your app we recommend using
99-
[**DexGuard**](http://www.guardsquare.com/dexguard), **ProGuard**'s
100-
closed-source sibling for Android, which offers
101-
multiple levels of code hardening and RASP (runtime application self-protection) for mobile apps and SDKs.
102-
103-
The **ProGuard** [keep rules configuration format](configuration/usage.md) is supported by R8,
95+
The **ProGuard** [keep rules configuration format](configuration/usage.md) is also supported by R8 (the default Android shrinker),
10496
so you can use your R8, ProGuard and DexGuard keep rules interchangeably.
105-
You can also make use of the [ProGuard Playground](https://playground.proguard.com) to visualize R8 rules.
97+
98+
See [Gradle Plugin setup](setup/gradleplugin.md) page for more information.
10699

107100
## Does ProGuard have support for Ant? {: #ant}
108101

@@ -111,15 +104,15 @@ your Ant build process. You can still use configurations in **ProGuard**'s own
111104
readable format. Alternatively, if you prefer XML, you can specify the
112105
equivalent XML configuration.
113106

114-
See [Ant setup](manual/setup/ant.md) page for more information.
107+
See [Ant setup](setup/ant.md) page for more information.
115108

116-
## Does ProGuard have support for Gradle? {: #gradle}
109+
## Does ProGuard have support for Java/Kotlin Gradle projects? {: #gradle}
117110

118111
Yes. **ProGuard** also provides a Gradle task, so that it integrates into your
119112
Gradle build process. You can specify configurations in **ProGuard**'s own
120113
format or embedded in the Groovy configuration.
121114

122-
See [Gradle setup](manual/setup/gradle.md) page for more information.
115+
See [Gradle setup](setup/gradle.md) page for more information.
123116

124117
## Does ProGuard have support for Maven? {: #maven}
125118

docs/md/manual/configuration/usage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ This page lists all available options for ProGuard, grouped logically.
583583
Standard Edition. For example, you will need this option if you are
584584
[processing midlets](examples.md#midlets).
585585

586+
`-android`{: #android}
587+
: Specifies that the processed class files are targeted at the Android
588+
platform. ProGuard then makes sure some features are compatible with
589+
Android.
590+
586591
## General Options {: #generaloptions}
587592

588593
`-verbose`{: #verbose}

docs/md/manual/quickstart.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ For more detailed information see [standalone mode](setup/standalone.md).
3636

3737
The ProGuard artifacts are hosted at [Maven Central](https://search.maven.org/search?q=g:com.guardsquare).
3838

39+
### Android Gradle project
40+
41+
When working on your Android application (apk, aab) or library (aar), you can include ProGuard in your Gradle build by:
42+
43+
- Using ProGuard's Gradle plugin, which you can apply in your `build.gradle` file (AGP 4.x - 7.x).
44+
- Using the integrated ProGuard by disabling R8 in your `gradle.properties` (only applicable for AGP < 7).
45+
46+
For more detailed information see [Android Gradle](setup/gradleplugin.md).
47+
3948
### Java or Kotlin Gradle project
4049

4150
Your non-mobile Java or Kotlin applications can execute ProGuard's Gradle task:
@@ -47,15 +56,6 @@ task myProguardTask(type: proguard.gradle.ProGuardTask) {
4756

4857
For more detailed information see [Java/Kotlin Gradle](setup/gradle.md).
4958

50-
### Android Gradle project
51-
52-
The default Android shrinker R8 is fully compatible with ProGuard keep rules.
53-
You can refer to the [configuration](usage.md) guide for help with keep rules or use
54-
the [ProGuard Playground](https://playground.proguard.com/) to visualise keep rules.
55-
56-
For setup and integration, please [follow the instructions to enable R8](https://developer.android.com/studio/build/shrink-code).
57-
58-
5959
### Ant project
6060

6161
You can also include ProGuard in your Ant build, all you have to do is to include the related task into your `build.xml` file:

docs/md/manual/refcard.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Typically:
6969
| [`-adaptresourcefilecontents`](configuration/usage.md#adaptresourcefilecontents) \[[*file\_filter*](configuration/usage.md#filefilters)\] | Update the contents of the specified resource files, based on the obfuscated names of the processed classes.
7070
| [`-dontpreverify`](configuration/usage.md#dontpreverify) | Don't preverify the processed class files.
7171
| [`-microedition`](configuration/usage.md#microedition) | Target the processed class files at Java Micro Edition.
72+
| [`-android`](configuration/usage.md#android) | Target the processed class files at Android.
7273
| [`-verbose`](configuration/usage.md#verbose) | Write out some more information during processing.
7374
| [`-dontnote`](configuration/usage.md#dontnote) \[[*class\_filter*](configuration/usage.md#filters)\] | Don't print notes about potential mistakes or omissions in the configuration.
7475
| [`-dontwarn`](configuration/usage.md#dontwarn) \[[*class\_filter*](configuration/usage.md#filters)\] | Don't warn about unresolved references at all.

docs/md/manual/setup/gradle.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
(version 2.1 or higher).
33

44
!!! android "Android projects"
5-
If you have an Android project, please refer to the instructions for integrating the
6-
[default shrinker R8](https://developer.android.com/studio/build/shrink-code) which is
7-
compatible with ProGuard keep rule configuration.
5+
If you have an Android project, you can find instructions [here](gradleplugin.md).
86

97

108
Before you can use the **`proguard`** task, you have to make sure Gradle can

docs/md/manual/setup/gradleplugin.md

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
2+
This page will guide you through to the basic steps of processing your Android application or library with ProGuard.
3+
4+
!!! tip "Java / Kotlin desktop or server projects"
5+
If you have a Java / Kotlin desktop or server project, you can find instructions [here](gradle.md).
6+
7+
## ProGuard Gradle Plugin (AGP version 4.x - AGP 7.x)
8+
9+
You can add the ProGuard plugin to your project by
10+
including the following in your root level `build.gradle(.kts)` file:
11+
12+
=== "Groovy"
13+
```Groovy
14+
buildscript {
15+
repositories {
16+
google() // For the Android Gradle plugin.
17+
mavenCentral() // For the ProGuard Gradle Plugin and anything else.
18+
}
19+
dependencies {
20+
classpath 'com.android.tools.build:gradle:x.y.z' // The Android Gradle plugin.
21+
classpath 'com.guardsquare:proguard-gradle:7.1.0' // The ProGuard Gradle plugin.
22+
}
23+
}
24+
```
25+
=== "Kotlin"
26+
```kotlin
27+
buildscript {
28+
repositories {
29+
google() // For the Android Gradle plugin.
30+
mavenCentral() // For the ProGuard Gradle Plugin and anything else.
31+
}
32+
dependencies {
33+
classpath("com.android.tools.build:gradle:x.y.z") // The Android Gradle plugin.
34+
classpath("com.guardsquare:proguard-gradle:7.1.0") // The ProGuard Gradle plugin.
35+
}
36+
}
37+
```
38+
39+
To actually apply the plugin to your project,
40+
just add the line to your module level `build.gradle(.kts)` file after applying the Android Gradle plugin as shown below.
41+
42+
=== "Groovy"
43+
```Groovy
44+
apply plugin: 'com.android.application'
45+
apply plugin: 'com.guardsquare.proguard'
46+
```
47+
=== "Kotlin"
48+
```kotlin
49+
plugins {
50+
id("com.android.application")
51+
id("proguard")
52+
}
53+
```
54+
55+
ProGuard expects unobfuscated class files as input. Therefore, other obfuscators such as R8 have to be disabled.
56+
57+
=== "Groovy"
58+
```Groovy
59+
android {
60+
...
61+
buildTypes {
62+
release {
63+
// Deactivate R8.
64+
minifyEnabled false
65+
}
66+
}
67+
}
68+
```
69+
=== "Kotlin"
70+
```kotlin
71+
android {
72+
...
73+
buildTypes {
74+
getByName("release") {
75+
// Deactivate R8.
76+
isMinifyEnabled = false
77+
}
78+
}
79+
}
80+
```
81+
82+
ProGuard can be executed automatically whenever you build any of the configured variants.
83+
You can configure a variant using the `proguard` block in your module level `build.gradle(.kts)` files.
84+
This is a top-level block and should be placed outside the `android` block.
85+
86+
For example, in the snippet below, ProGuard is configured to only process the release variant of the application,
87+
using a configuration provided by the user (`proguard-project.txt`) and a [default configuration](#default-configurations) (`proguard-android-optimize.txt`).
88+
89+
=== "Groovy"
90+
```Groovy
91+
android {
92+
...
93+
}
94+
95+
proguard {
96+
configurations {
97+
release {
98+
defaultConfiguration 'proguard-android-optimize.txt'
99+
configuration 'proguard-project.txt'
100+
}
101+
}
102+
}
103+
```
104+
=== "Kotlin"
105+
```kotlin
106+
android {
107+
...
108+
}
109+
110+
proguard {
111+
configurations {
112+
register("release") {
113+
defaultConfiguration("proguard-android-optimize.txt")
114+
configuration("proguard-project.txt")
115+
}
116+
}
117+
}
118+
```
119+
120+
You can then build your application as usual:
121+
122+
=== "Linux/macOS"
123+
```sh
124+
./gradlew assembleRelease
125+
```
126+
=== "Windows"
127+
```
128+
gradlew assembleRelease
129+
```
130+
131+
### Default configurations
132+
133+
There are three default configurations available:
134+
135+
| Default configuration | Description |
136+
|-----------------------|-------------|
137+
| `proguard-android.txt` | ProGuard will obfuscate and shrink your application |
138+
| `proguard-android-optimize.txt` | ProGuard will obfuscate, shrink and optimize your application |
139+
| `proguard-android-debug.txt` | ProGuard will process the application without any obfuscation,<br>optimization or shrinking |
140+
141+
### Consumer rules
142+
143+
ProGuard will apply the consumer rules provided by library dependencies. If you need to exclude these rules,
144+
you can use the `consumerRuleFilter`.
145+
146+
#### consumerRuleFilter
147+
148+
The `consumerRuleFilter` option allows you to specify a list of maven group and
149+
module name pairs to filter out the ProGuard consumer rules of the dependencies
150+
that match the specified group and module pairs.
151+
152+
A group and module name pair is very similar to the maven coordinates you write
153+
when specifying the dependencies in the `dependencies` block, but without the
154+
version part.
155+
156+
=== "Groovy"
157+
```Groovy
158+
proguard {
159+
configurations {
160+
release {
161+
consumerRuleFilter 'groupName:moduleName', 'anotherGroupName:anotherModuleName'
162+
}
163+
}
164+
}
165+
```
166+
=== "Kotlin"
167+
```Kotlin
168+
proguard {
169+
configurations {
170+
register("release") {
171+
consumerRuleFilter("groupName:moduleName", "anotherGroupName:anotherModuleName")
172+
}
173+
}
174+
}
175+
```
176+
177+
### Example
178+
179+
The example [`android-plugin`](https://github.com/Guardsquare/proguard/tree/master/examples/android-plugin)
180+
has a small working Android project using the ProGuard Gradle Plugin.
181+
182+
## AGP Integrated ProGuard (AGP version <7)
183+
184+
ProGuard is integrated with older versions of the Android Gradle plugin.
185+
If you have an Android Gradle project that uses such an AGP version,
186+
you can enable ProGuard instead of the default `R8` obfuscator as follows:
187+
188+
1. Disable R8 in your `gradle.properties`:
189+
```ini
190+
android.enableR8=false
191+
android.enableR8.libraries=false
192+
```
193+
194+
2. Override the default version of ProGuard with the most recent one in your
195+
main `build.gradle`:
196+
```Groovy
197+
buildscript {
198+
...
199+
configurations.all {
200+
resolutionStrategy {
201+
dependencySubstitution {
202+
substitute module('net.sf.proguard:proguard-gradle') with module('com.guardsquare:proguard-gradle:7.1.0')
203+
}
204+
}
205+
}
206+
}
207+
```
208+
209+
3. Enable minification as usual in your `build.gradle`:
210+
```Groovy
211+
android {
212+
...
213+
buildTypes {
214+
release {
215+
minifyEnabled true
216+
shrinkResources true
217+
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
218+
proguardFile 'proguard-project.txt'
219+
}
220+
}
221+
}
222+
```
223+
224+
There are two default configurations available when using the integrated ProGuard:
225+
226+
| Default configuration | Description |
227+
|-----------------------|-------------|
228+
| `proguard-android.txt` | ProGuard will obfuscate and shrink your application |
229+
| `proguard-android-optimize.txt` | ProGuard will obfuscate, shrink and optimize your application |
230+
231+
4. Add any necessary configuration to your `proguard-project.txt`.
232+
233+
You can then build your application as usual:
234+
235+
=== "Linux/macOS"
236+
```sh
237+
./gradlew assembleRelease
238+
```
239+
=== "Windows"
240+
```
241+
gradlew assembleRelease
242+
```
243+
244+
### Example
245+
246+
The example [`android-agp3-agp4`](https://github.com/Guardsquare/proguard/tree/master/examples/android-agp3-agp4)
247+
has a small working Android project for AGP < 7.
248+
249+
250+

docs/mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ nav:
7777
- Building: manual/building.md
7878
- Setup:
7979
- Standalone: manual/setup/standalone.md
80-
- Gradle: manual/setup/gradle.md
80+
- Android Gradle: manual/setup/gradleplugin.md
81+
- Java/Kotlin Gradle: manual/setup/gradle.md
8182
- Ant Task: manual/setup/ant.md
8283
- Configuration:
8384
- Usage: manual/configuration/usage.md
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
<application android:label="@string/app_name"
7+
android:icon="@drawable/ic_launcher"
8+
android:theme="@style/AppTheme">
9+
<activity android:name="HelloWorldActivity"
10+
android:label="@string/app_name">
11+
<intent-filter>
12+
<action android:name="android.intent.action.MAIN" />
13+
<category android:name="android.intent.category.LAUNCHER" />
14+
</intent-filter>
15+
</activity>
16+
</application>
17+
</manifest>

0 commit comments

Comments
 (0)