Skip to content

Commit 764d35e

Browse files
Update manual (#321)
* Update manual * Delete and --------- Co-authored-by: James Hamilton <[email protected]>
1 parent 745a681 commit 764d35e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+101
-2291
lines changed

README.md

Lines changed: 48 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ bytecode:
5757
* It renames the remaining classes, fields, and methods using short
5858
meaningless names.
5959

60-
The resulting applications and libraries are smaller, faster, and a bit better
61-
hardened against reverse engineering. ProGuard is very popular for Android
62-
development, but it also works for Java code in general.
60+
The resulting applications and libraries are smaller and faster.
6361

6462
## ❓ Getting Help
6563
If you have **usage or general questions** please ask them in the <a href="https://community.guardsquare.com/?utm_source=github&utm_medium=site-link&utm_campaign=github-community">**Guardsquare Community**.</a>
@@ -69,129 +67,79 @@ Please use <a href="https://github.com/guardsquare/proguard/issues">**the issue
6967

7068
## 🚀 Quick Start
7169

72-
ProGuard has its own Gradle plugin, allowing you to shrink, optimize and obfuscate Android projects.
70+
### Command line
7371

74-
### ProGuard Gradle Plugin
72+
First, download the latest release from [GitHub releases](https://github.com/Guardsquare/proguard/releases).
7573

76-
You can apply the ProGuard Gradle plugin in AGP 4+ projects by following these steps:
74+
To run ProGuard, on Linux/MacOS, just type:
7775

78-
1. Add a `classpath` dependency in your root level `build.gradle` file:
79-
80-
```Groovy
81-
buildscript {
82-
repositories {
83-
google() // For the Android Gradle plugin.
84-
mavenCentral() // For the ProGuard Gradle Plugin and anything else.
85-
}
86-
dependencies {
87-
classpath 'com.android.tools.build:gradle:x.y.z' // The Android Gradle plugin.
88-
classpath 'com.guardsquare:proguard-gradle:7.3.0' // The ProGuard Gradle plugin.
89-
}
90-
}
76+
```bash
77+
bin/proguard.sh <options...>
9178
```
9279

93-
2. Apply the `proguard` plugin after applying the Android Gradle plugin as shown below:
80+
or on Windows:
9481

95-
```Groovy
96-
apply plugin: 'com.android.application'
97-
apply plugin: 'com.guardsquare.proguard'
9882
```
99-
100-
3. ProGuard expects unobfuscated class files as input. Therefore, other obfuscators such as R8 have to be disabled.
101-
102-
```Groovy
103-
android {
104-
...
105-
buildTypes {
106-
release {
107-
// Deactivate R8.
108-
minifyEnabled false
109-
}
110-
}
111-
}
83+
bin\proguard <options...>
11284
```
11385

114-
4. Configure variants to be processed with ProGuard using the `proguard` block:
115-
116-
```Groovy
117-
android {
118-
...
119-
}
86+
Typically, you'll put most options in a configuration file (say,
87+
`myconfig.pro`), and just call
12088

121-
proguard {
122-
configurations {
123-
release {
124-
defaultConfiguration 'proguard-android-optimize.txt'
125-
configuration 'proguard-project.txt'
126-
}
127-
}
128-
}
89+
```bash
90+
bin/proguard.sh @myconfig.pro
12991
```
92+
or on Windows:
13093

131-
You can then build your application as usual:
132-
133-
```shell
134-
gradle assembleRelease
94+
```
95+
bin\proguard @myconfig.pro
13596
```
13697

137-
The repository contains some sample configurations in the [examples](examples)
138-
directory. Notably, [examples/android](examples/android-plugin) has a small working
139-
Android project that applies the ProGuard Gradle plugin.
140-
141-
### Integrated ProGuard (AGP < 7.0)
142-
143-
If you have an older Android Gradle project you can enable ProGuard instead of the default R8 compiler:
144-
145-
1. Disable R8 in your `gradle.properties`:
98+
All available options are described in the [Configuration section](../configuration/usage.md).
14699

147-
```gradle
148-
android.enableR8=false
149-
android.enableR8.libraries=false
150-
```
100+
### Gradle Task
151101

152-
2. Override the default version of ProGuard with the most recent one in your
153-
main `build.gradle`:
102+
ProGuard can be run as a task in Gradle. Before you can use the proguard task, you have to make sure Gradle can
103+
find it in its class path at build time. One way is to add the following
104+
line to your **`build.gradle`** file which will download ProGuard from Maven Central:
154105

155-
```gradle
106+
```Groovy
156107
buildscript {
157-
//...
158-
configurations.all {
159-
resolutionStrategy {
160-
dependencySubstitution {
161-
substitute module('net.sf.proguard:proguard-gradle') with module('com.guardsquare:proguard-gradle:7.3.0')
162-
}
163-
}
108+
repositories {
109+
mavenCentral()
164110
}
165-
}
166-
```
167-
168-
3. Enable minification as usual in your `build.gradle`:
169-
170-
```gradle
171-
android {
172-
//...
173-
buildTypes {
174-
release {
175-
minifyEnabled true
176-
shrinkResources true
177-
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
178-
proguardFile 'proguard-project.txt'
179-
}
111+
dependencies {
112+
classpath 'com.guardsquare:proguard-gradle:7.1.0'
180113
}
181114
}
182115
```
183116

184-
4. Add any necessary configuration to your `proguard-project.txt`.
117+
You can then define a task with configuration:
185118

186-
You can then build your application as usual:
119+
```Groovy
120+
tasks.register('proguard', ProGuardTask) {
121+
configuration file('proguard.pro')
122+
123+
injars(tasks.named('jar', Jar).flatMap { it.archiveFile })
124+
125+
// Automatically handle the Java version of this build.
126+
if (System.getProperty('java.version').startsWith('1.')) {
127+
// Before Java 9, the runtime classes were packaged in a single jar file.
128+
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
129+
} else {
130+
// As of Java 9, the runtime classes are packaged in modular jmod files.
131+
libraryjars "${System.getProperty('java.home')}/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
132+
//libraryjars "${System.getProperty('java.home')}/jmods/....."
133+
}
187134
188-
```shell
189-
gradle assembleRelease
135+
verbose
136+
137+
outjars(layout.buildDirectory.file("libs/${baseCoordinates}-minified.jar"))
138+
}
190139
```
191140

192-
The repository contains some sample configurations in the [examples](examples)
193-
directory. Notably, [examples/android-agp3-agp4](examples/android-agp3-agp4) has a small working
194-
Android project that uses the old integration.
141+
The embedded configuration is much like a standard ProGuard
142+
configuration. You can find more details on the [Gradle setup page](setup/gradle.md#proguard).
195143

196144
## ✨ Features
197145

@@ -205,8 +153,7 @@ inlining methods, propagating constants, removing unused parameters, etc.
205153

206154
* The optimizations may also improve the performance of the application, by up
207155
to 20%. For Java virtual machines on servers and desktops, the difference
208-
generally isn't noticeable. For the Dalvik virtual machine and ART on
209-
Android devices, the difference can be worth it.
156+
generally isn't noticeable.
210157

211158
* ProGuard can also remove logging code, from applications and their
212159
libraries, without needing to change the source code &mdash; in fact,

docs/md/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ hardened against reverse engineering.
77

88
Typical applications:
99

10-
- Reducing the size of Android apps for faster downloads, shorter startup
10+
- Reducing the size of apps for faster downloads, shorter startup
1111
times, and smaller memory footprints.
1212
- Optimizing code for better performance on mobile devices.
1313

docs/md/FAQ.md renamed to docs/md/manual/FAQ.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ Shrinking programs such as **ProGuard** can analyze bytecode and remove unused
77
classes, fields, and methods. The program remains functionally equivalent,
88
including the information given in exception stack traces.
99

10-
## What is obfuscation? {: #obfuscation}
10+
## What is name obfuscation? {: #obfuscation}
1111

1212
By default, compiled bytecode still contains a lot of debugging information:
1313
source file names, line numbers, field names, method names, argument names,
1414
variable names, etc. This information makes it straightforward to decompile
1515
the bytecode and reverse-engineer entire programs. Sometimes, this is not
16-
desirable. Obfuscators such as **ProGuard** can remove the debugging
16+
desirable. Shrinkers such as **ProGuard** can remove the debugging
1717
information and replace all names by meaningless character sequences, making
18-
it much harder to reverse-engineer the code. It further compacts the code as a
19-
bonus. The program remains functionally equivalent, except for the class
18+
apps smaller. The program remains functionally equivalent, except for the class
2019
names, method names, and line numbers given in exception stack traces.
2120

2221
## What is preverification? {: #preverification}
@@ -71,7 +70,7 @@ license can remain the same.
7170

7271
## Does ProGuard work with Java 2, 5,..., 15? {: #jdk1.4}
7372

74-
Yes, **ProGuard** supports all JDKs from 1.1 up to and including 15. Java 2
73+
Yes, **ProGuard** supports all JDKs from 1.1 up to and including 19. Java 2
7574
introduced some small differences in the class file format. Java 5 added
7675
attributes for generics and for annotations. Java 6 introduced optional
7776
preverification attributes. Java 7 made preverification obligatory and
@@ -89,18 +88,21 @@ including Java Micro Edition. **ProGuard** then also performs the required
8988
preverification, producing more compact results than the traditional external
9089
preverifier.
9190

92-
**ProGuard** also comes with an obfuscator plug-in for the JME Wireless
93-
Toolkit.
91+
## Does ProGuard Support Android Apps?
9492

95-
## Does ProGuard work for Android apps?
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.
9696

97-
Yes. Google's dx and D8 compilers convert Java bytecode into the Dalvik
98-
bytecode that runs on Android devices. By preprocessing the original bytecode,
99-
**ProGuard** can significantly reduce the file sizes and boost the run-time
100-
performance of the code. It is distributed as part of the Android SDK.
97+
However, R8 is only a shrinker & optimizer and does not provide any security features.
98+
To protect your app we recommend using
10199
[**DexGuard**](http://www.guardsquare.com/dexguard), **ProGuard**'s
102-
closed-source sibling for Android, offers additional optimizations and more
103-
application protection.
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,
104+
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.
104106

105107
## Does ProGuard have support for Ant? {: #ant}
106108

@@ -109,21 +111,26 @@ your Ant build process. You can still use configurations in **ProGuard**'s own
109111
readable format. Alternatively, if you prefer XML, you can specify the
110112
equivalent XML configuration.
111113

114+
See [Ant setup](manual/setup/ant.md) page for more information.
115+
112116
## Does ProGuard have support for Gradle? {: #gradle}
113117

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

122+
See [Gradle setup](manual/setup/gradle.md) page for more information.
123+
118124
## Does ProGuard have support for Maven? {: #maven}
119125

120-
**ProGuard**'s jar files are also distributed as artefacts from the [Maven
121-
Central](http://search.maven.org/#search%7Cga%7C1%7Cg:%22com.guardsquare%22)
122-
repository. There are some third-party plugins that support **ProGuard**, such
123-
as the [android-maven-plugin](http://code.google.com/p/maven-android-plugin/)
124-
and the [IDFC Maven ProGuard Plug-in](http://mavenproguard.sourceforge.net/).
125-
[**DexGuard**](http://www.guardsquare.com/dexguard) also comes with a Maven
126-
plugin.
126+
While we don't officially provide a Maven integration and
127+
we cannot provide support there are solutions available,
128+
their offered functionality is not guaranteed by Guardsquare.
129+
130+
Some open-source implementations:
131+
132+
- [https://github.com/wvengen/proguard-maven-plugin](https://github.com/wvengen/proguard-maven-plugin)
133+
- [https://github.com/dingxin/proguard-maven-plugin](https://github.com/dingxin/proguard-maven-plugin)
127134

128135
## Does ProGuard come with a GUI? {: #gui}
129136

@@ -195,9 +202,6 @@ is presented for each obfuscated method name that has an ambiguous reverse
195202
mapping. Please refer to the [ProGuard User Manual](manual/index.md) for more
196203
details.
197204

198-
Erik André at Badoo has written a [tool to de-obfuscate HPROF memory
199-
dumps](https://techblog.badoo.com/blog/2014/10/08/deobfuscating-hprof-memory-dumps/).
200-
201205
## How is DexGuard different from ProGuard?
202206

203207
[**DexGuard**](http://www.guardsquare.com/dexguard) is a commercial extension

0 commit comments

Comments
 (0)