Skip to content

Commit

Permalink
Update manual
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjameshamilton committed Mar 17, 2023
1 parent aa1835f commit 1b44559
Show file tree
Hide file tree
Showing 36 changed files with 1,393 additions and 28 deletions.
23 changes: 8 additions & 15 deletions docs/md/manual/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Yes, you can. **ProGuard** itself is distributed under the GPL, but this
doesn't affect the programs that you process. Your code remains yours, and its
license can remain the same.

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

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

## Does ProGuard Support Android Apps?

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

However, R8 is only a shrinker & optimizer and does not provide any security features.
To protect your app we recommend using
[**DexGuard**](http://www.guardsquare.com/dexguard), **ProGuard**'s
closed-source sibling for Android, which offers
multiple levels of code hardening and RASP (runtime application self-protection) for mobile apps and SDKs.

The **ProGuard** [keep rules configuration format](configuration/usage.md) is supported by R8,
The **ProGuard** [keep rules configuration format](configuration/usage.md) is also supported by R8 (the default Android shrinker),
so you can use your R8, ProGuard and DexGuard keep rules interchangeably.
You can also make use of the [ProGuard Playground](https://playground.proguard.com) to visualize R8 rules.

See [Gradle Plugin setup](setup/gradleplugin.md) page for more information.

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

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

See [Ant setup](manual/setup/ant.md) page for more information.
See [Ant setup](setup/ant.md) page for more information.

## Does ProGuard have support for Gradle? {: #gradle}
## Does ProGuard have support for Java/Kotlin Gradle projects? {: #gradle}

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

See [Gradle setup](manual/setup/gradle.md) page for more information.
See [Gradle setup](setup/gradle.md) page for more information.

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

Expand Down
5 changes: 5 additions & 0 deletions docs/md/manual/configuration/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ This page lists all available options for ProGuard, grouped logically.
Standard Edition. For example, you will need this option if you are
[processing midlets](examples.md#midlets).

`-android`{: #android}
: Specifies that the processed class files are targeted at the Android
platform. ProGuard then makes sure some features are compatible with
Android.

## General Options {: #generaloptions}

`-verbose`{: #verbose}
Expand Down
18 changes: 9 additions & 9 deletions docs/md/manual/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ For more detailed information see [standalone mode](setup/standalone.md).

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

### Android Gradle project

When working on your Android application (apk, aab) or library (aar), you can include ProGuard in your Gradle build by:

- Using ProGuard's Gradle plugin, which you can apply in your `build.gradle` file (AGP 4.x - 7.x).
- Using the integrated ProGuard by disabling R8 in your `gradle.properties` (only applicable for AGP < 7).

For more detailed information see [Android Gradle](setup/gradleplugin.md).

### Java or Kotlin Gradle project

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

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

### Android Gradle project

The default Android shrinker R8 is fully compatible with ProGuard keep rules.
You can refer to the [configuration](usage.md) guide for help with keep rules or use
the [ProGuard Playground](https://playground.proguard.com/) to visualise keep rules.

For setup and integration, please [follow the instructions to enable R8](https://developer.android.com/studio/build/shrink-code).


### Ant project

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:
Expand Down
1 change: 1 addition & 0 deletions docs/md/manual/refcard.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Typically:
| [`-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.
| [`-dontpreverify`](configuration/usage.md#dontpreverify) | Don't preverify the processed class files.
| [`-microedition`](configuration/usage.md#microedition) | Target the processed class files at Java Micro Edition.
| [`-android`](configuration/usage.md#android) | Target the processed class files at Android.
| [`-verbose`](configuration/usage.md#verbose) | Write out some more information during processing.
| [`-dontnote`](configuration/usage.md#dontnote) \[[*class\_filter*](configuration/usage.md#filters)\] | Don't print notes about potential mistakes or omissions in the configuration.
| [`-dontwarn`](configuration/usage.md#dontwarn) \[[*class\_filter*](configuration/usage.md#filters)\] | Don't warn about unresolved references at all.
Expand Down
4 changes: 1 addition & 3 deletions docs/md/manual/setup/gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
(version 2.1 or higher).

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


Before you can use the **`proguard`** task, you have to make sure Gradle can
Expand Down
250 changes: 250 additions & 0 deletions docs/md/manual/setup/gradleplugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@

This page will guide you through to the basic steps of processing your Android application or library with ProGuard.

!!! tip "Java / Kotlin desktop or server projects"
If you have a Java / Kotlin desktop or server project, you can find instructions [here](gradle.md).

## ProGuard Gradle Plugin (AGP version 4.x - AGP 7.x)

You can add the ProGuard plugin to your project by
including the following in your root level `build.gradle(.kts)` file:

=== "Groovy"
```Groovy
buildscript {
repositories {
google() // For the Android Gradle plugin.
mavenCentral() // For the ProGuard Gradle Plugin and anything else.
}
dependencies {
classpath 'com.android.tools.build:gradle:x.y.z' // The Android Gradle plugin.
classpath 'com.guardsquare:proguard-gradle:7.1.0' // The ProGuard Gradle plugin.
}
}
```
=== "Kotlin"
```kotlin
buildscript {
repositories {
google() // For the Android Gradle plugin.
mavenCentral() // For the ProGuard Gradle Plugin and anything else.
}
dependencies {
classpath("com.android.tools.build:gradle:x.y.z") // The Android Gradle plugin.
classpath("com.guardsquare:proguard-gradle:7.1.0") // The ProGuard Gradle plugin.
}
}
```

To actually apply the plugin to your project,
just add the line to your module level `build.gradle(.kts)` file after applying the Android Gradle plugin as shown below.

=== "Groovy"
```Groovy
apply plugin: 'com.android.application'
apply plugin: 'com.guardsquare.proguard'
```
=== "Kotlin"
```kotlin
plugins {
id("com.android.application")
id("proguard")
}
```

ProGuard expects unobfuscated class files as input. Therefore, other obfuscators such as R8 have to be disabled.

=== "Groovy"
```Groovy
android {
...
buildTypes {
release {
// Deactivate R8.
minifyEnabled false
}
}
}
```
=== "Kotlin"
```kotlin
android {
...
buildTypes {
getByName("release") {
// Deactivate R8.
isMinifyEnabled = false
}
}
}
```

ProGuard can be executed automatically whenever you build any of the configured variants.
You can configure a variant using the `proguard` block in your module level `build.gradle(.kts)` files.
This is a top-level block and should be placed outside the `android` block.

For example, in the snippet below, ProGuard is configured to only process the release variant of the application,
using a configuration provided by the user (`proguard-project.txt`) and a [default configuration](#default-configurations) (`proguard-android-optimize.txt`).

=== "Groovy"
```Groovy
android {
...
}

proguard {
configurations {
release {
defaultConfiguration 'proguard-android-optimize.txt'
configuration 'proguard-project.txt'
}
}
}
```
=== "Kotlin"
```kotlin
android {
...
}

proguard {
configurations {
register("release") {
defaultConfiguration("proguard-android-optimize.txt")
configuration("proguard-project.txt")
}
}
}
```

You can then build your application as usual:

=== "Linux/macOS"
```sh
./gradlew assembleRelease
```
=== "Windows"
```
gradlew assembleRelease
```

### Default configurations

There are three default configurations available:

| Default configuration | Description |
|-----------------------|-------------|
| `proguard-android.txt` | ProGuard will obfuscate and shrink your application |
| `proguard-android-optimize.txt` | ProGuard will obfuscate, shrink and optimize your application |
| `proguard-android-debug.txt` | ProGuard will process the application without any obfuscation,<br>optimization or shrinking |

### Consumer rules

ProGuard will apply the consumer rules provided by library dependencies. If you need to exclude these rules,
you can use the `consumerRuleFilter`.

#### consumerRuleFilter

The `consumerRuleFilter` option allows you to specify a list of maven group and
module name pairs to filter out the ProGuard consumer rules of the dependencies
that match the specified group and module pairs.

A group and module name pair is very similar to the maven coordinates you write
when specifying the dependencies in the `dependencies` block, but without the
version part.

=== "Groovy"
```Groovy
proguard {
configurations {
release {
consumerRuleFilter 'groupName:moduleName', 'anotherGroupName:anotherModuleName'
}
}
}
```
=== "Kotlin"
```Kotlin
proguard {
configurations {
register("release") {
consumerRuleFilter("groupName:moduleName", "anotherGroupName:anotherModuleName")
}
}
}
```

### Example

The example [`android-plugin`](https://github.com/Guardsquare/proguard/tree/master/examples/android-plugin)
has a small working Android project using the ProGuard Gradle Plugin.

## AGP Integrated ProGuard (AGP version <7)

ProGuard is integrated with older versions of the Android Gradle plugin.
If you have an Android Gradle project that uses such an AGP version,
you can enable ProGuard instead of the default `R8` obfuscator as follows:

1. Disable R8 in your `gradle.properties`:
```ini
android.enableR8=false
android.enableR8.libraries=false
```

2. Override the default version of ProGuard with the most recent one in your
main `build.gradle`:
```Groovy
buildscript {
...
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module('net.sf.proguard:proguard-gradle') with module('com.guardsquare:proguard-gradle:7.1.0')
}
}
}
}
```

3. Enable minification as usual in your `build.gradle`:
```Groovy
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
proguardFile 'proguard-project.txt'
}
}
}
```

There are two default configurations available when using the integrated ProGuard:

| Default configuration | Description |
|-----------------------|-------------|
| `proguard-android.txt` | ProGuard will obfuscate and shrink your application |
| `proguard-android-optimize.txt` | ProGuard will obfuscate, shrink and optimize your application |

4. Add any necessary configuration to your `proguard-project.txt`.

You can then build your application as usual:

=== "Linux/macOS"
```sh
./gradlew assembleRelease
```
=== "Windows"
```
gradlew assembleRelease
```

### Example

The example [`android-agp3-agp4`](https://github.com/Guardsquare/proguard/tree/master/examples/android-agp3-agp4)
has a small working Android project for AGP < 7.



3 changes: 2 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ nav:
- Building: manual/building.md
- Setup:
- Standalone: manual/setup/standalone.md
- Gradle: manual/setup/gradle.md
- Android Gradle: manual/setup/gradleplugin.md
- Java/Kotlin Gradle: manual/setup/gradle.md
- Ant Task: manual/setup/ant.md
- Configuration:
- Usage: manual/configuration/usage.md
Expand Down
17 changes: 17 additions & 0 deletions examples/android-agp3-agp4/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<activity android:name="HelloWorldActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Loading

0 comments on commit 1b44559

Please sign in to comment.