Cannot apply ProGuard Gradle Plugin in an Android project

Hi

I use Android Studio 4.1.2 to create a new project.

And try to enable proguard by using ProGuard Gradle Plugin, ProGuard manual | Gradle plugin | Guardsquare

After doing gradle sync in Android Studio, I got the following error.

Unable to load class ‘com.android.builder.core.AndroidBuilder’.

This is an unexpected error. Please file a bug containing the idea.log file.

Hi @paulhsu !

Our current ProGuard plugin is unfortunately not compatible with AGP 3.5+. This class used by our plugin was removed in AGP 3.5: ‘com.android.builder.core.AndroidBuilder’.

To use the current plugin, you’ll have to downgrade to AGP 3.4.

We’re working on a new plugin that will support newer AGP versions but it’s not available yet.

2 Likes

Hi James,

I tried another way to enable proguard in my project.

I got the following error:

The option setting ‘android.enableR8=false’ is deprecated.

And this,

Task :omniNotes:minifyFossDebugWithProguard FAILED

Execution failed for task ‘:omniNotes:minifyFossDebugWithProguard’.

proguard.KeepClassSpecification.(ZZZZZZZLproguard/ClassSpecification;Lproguard/ClassSpecification;)V

Paul

The ‘android.enableR8=false’ is deprecated is an expected warning.

For the other error, you should not be getting that. Could you share your build.gradle files or the full project?

hi @james

the project I use

I am trying to use proguard to do some experiments in this project

Hi @paulhsu ,

you should only need to change the following:

  • disable R8 in gradle.properties
  • add the ProGuard plugin to the buildscripts dependencies in the root build.gradle
  • you can also ignore the warnings in the omniNotes/proguard-rules.txt file as if you don’t add this the build will fail telling you to correct the warnings
diff --git a/build.gradle b/build.gradle
index 1d186908..8465e4fe 100644
--- a/build.gradle
+++ b/build.gradle
@@ -26,6 +26,7 @@ buildscript {
         classpath 'com.android.tools.build:gradle:4.1.1'
         classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0"
         classpath 'com.adarshr:gradle-test-logger-plugin:2.1.0'
+        classpath 'com.guardsquare:proguard-gradle:7.0.1'
     }
     // Exclude the version that the android plugin depends on.
     configurations.classpath.exclude group: 'com.android.tools.external.lombok'
diff --git a/gradle.properties b/gradle.properties
index c640714a..68a18599 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -42,3 +42,6 @@ CRASH_REPORTING_URL=
 VERSION_CHECK_URL=
 # Google Maps API key to provide addresses autocompletion feature
 MAPS_API_KEY=
+
+android.enableR8=false
+android.enableR8.libraries=false
diff --git a/omniNotes/proguard-rules.txt b/omniNotes/proguard-rules.txt
index 3b37fb6c..3ad677c7 100644
--- a/omniNotes/proguard-rules.txt
+++ b/omniNotes/proguard-rules.txt
@@ -5,6 +5,7 @@
 -dontskipnonpubliclibraryclasses
 -dontpreverify
 -verbose
+-ignorewarnings
 
 # The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle.
 -optimizations !code/simplification/arithmetic

Thanks @james .

I use my original project and you patch, it does not work.

But I re-clone the git repo then apply your patch.

It works without problem.

Paul

1 Like