Obfuscation

Answered

I have run proguard to obfuscate the plugin I am developing. I ran it on the zip file in the build/distributions folder. 

When I try to install the obfuscated plugin I get errors like: 

Caused by: java.lang.ClassNotFoundException: *** PluginClassLoader[***, 1.0-SNAPSHOT] com.intellij.ide.plugins.cl.PluginClassLoader@707a0b90
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:75)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at com.intellij.openapi.components.impl.ComponentManagerImpl.registerComponents(ComponentManagerImpl.java:386)

Just to note, when I install the plugin using the zip file that Intellij produces (no obfuscation), it installs fine.

It is mentioned in https://plugins.jetbrains.com/docs/marketplace/obfuscate-the-plugin.html that proguard has been used to obfuscate plugins. Could someone give me a little guidance as to how the obfuscation is configured?

Thanks.

0
3 comments

Please make sure you do not obfuscate classes that are defined in your plugin.xml

0

Thanks Yann. Having done that I now get an error like:


com.intellij.ide.plugins.MainRunner$StartupAbortedException: Fatal error initializing plugin ***
at com.intellij.ide.plugins.PluginManager.handleComponentError(PluginManager.java:118)
at com.intellij.openapi.components.impl.PlatformComponentManagerImpl.handleInitComponentError(PlatformComponentManagerImpl.java:33)
at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:520)
at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponents(ComponentManagerImpl.java:126)
at com.intellij.openapi.project.impl.ProjectImpl.init(ProjectImpl.java:262)
at com.intellij.openapi.project.impl.ProjectManagerImpl.initProject(ProjectManagerImpl.java:285)
at com.intellij.openapi.project.impl.ProjectManagerImpl.convertAndLoadProject(ProjectManagerImpl.java:599)
at com.intellij.platform.PlatformProjectOpenProcessor.tryLoadProject(PlatformProjectOpenProcessor.java:280)
at com.intellij.platform.PlatformProjectOpenProcessor.prepareAndOpenProject(PlatformProjectOpenProcessor.java:254)
at com.intellij.platform.PlatformProjectOpenProcessor.lambda$doOpenProject$0(PlatformProjectOpenProcessor.java:198)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:253)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:894)
at com.intellij.openapi.progress.impl.CoreProgressManager$5.run(CoreProgressManager.java:447)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:169)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:591)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:537)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:59)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:156)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$null$9(ApplicationImpl.java:552)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:294)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.intellij.diagnostic.PluginException: Either do the specified parameters not match any of the following constructors: [] or the constructors were not accessible for 'class ***' [Plugin: ***]
... 25 more
Caused by: org.picocontainer.PicoInitializationException: Either do the specified parameters not match any of the following constructors: [] or the constructors were not accessible for 'class ***'
at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.getGreediestSatisfiableConstructor(CachingConstructorInjectionComponentAdapter.java:172)
at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.doGetComponentInstance(CachingConstructorInjectionComponentAdapter.java:81)
at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.instantiateGuarded(CachingConstructorInjectionComponentAdapter.java:66)
at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.getComponentInstance(CachingConstructorInjectionComponentAdapter.java:48)
at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:481)
... 22 more

Think I need to change something in my proguard config. right now it looks like this:

-injars ***-SNAPSHOT.jar
-outjars ***-SNAPSHOT-obf.jar

-libraryjars /usr/lib/jvm/java-8-oracle/jre/lib/rt.jar
-libraryjars ***/ideaIC-2019.1.1/idea-IC-191.6707.61/lib/util.jar
-libraryjars ***/ideaIC-2019.1.1/idea-IC-191.6707.61/lib/extensions.jar
-libraryjars ***/ideaIC-2019.1.1/idea-IC-191.6707.61/lib/annotations.jar
-libraryjars ***/ideaIC-2019.1.1/idea-IC-191.6707.61/lib/platform-util-ui.jar
-libraryjars ***/ideaIC-2019.1.1/idea-IC-191.6707.61/lib/platform-core-ui.jar
-libraryjars ***/ideaIC-2019.1.1/idea-IC-191.6707.61/lib/platform-api.jar
-libraryjars ***/ideaIC-2019.1.1/idea-IC-191.6707.61/lib/openapi.jar
-libraryjars ***-SNAPSHOT/***/lib/gson-2.8.5.jar
-libraryjars searchableOptions-1.0-SNAPSHOT.jar

-target 1.8
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF
-verbose




-keep class MyClass1,MyClass2,...

# Keep - Applications. Keep all application classes, along with their 'main' methods.
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}

# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

# Also keep - Database drivers. Keep all implementations of java.sql.Driver.
-keep class * extends java.sql.Driver
# Also keep - Swing UI L&F. Keep all extensions of javax.swing.plaf.ComponentUI,
# along with the special 'createUI' method.
-keep class * extends javax.swing.plaf.ComponentUI {
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent);
}

-keep class com.intellij.util.* {*;}

The obfuscation step runs fine. I just get these run time errors when I try to run the obfuscated plugin. 

0

Make sure not to obfuscate any constructors and any types used there for anything registered in plugin.xml

0

Please sign in to leave a comment.