Proguard removes com.sun.mail.imap.IMAPProvider - java

In my app I send emails to some specific address, it all works fine, but when it comes to obfuscation, shrinking, etc with ProGuard it fails
I've tried adding some ProGuard rules, which didn't work
That's my ProGuard
-keepclassmembernames class com.sun.mail.imap
2019-08-08 14:29:26.811 11724-12675/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
Process: com.redegrow.besttaxi, PID: 11724
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
...
Caused by: java.util.ServiceConfigurationError: e.b.r: Provider com.sun.mail.imap.IMAPProvider not found
at java.util.ServiceLoader.fail(ServiceLoader.java:233)
at java.util.ServiceLoader.access$100(ServiceLoader.java:183)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:373)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
...
Caused by: java.lang.ClassNotFoundException: com.sun.mail.imap.IMAPProvider
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.mail.imap.IMAPProvider" on path: DexPathList[[zip file "/data/app/com.redegrow.besttaxi-_Kl-yVNRgbmmwzLXuKKmWQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.redegrow.besttaxi-_Kl-yVNRgbmmwzLXuKKmWQ==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
...

Well, I found the solution.
It's not great, but at least it works
-keep class com.sun.mail.imap.IMAPProvider
-keep class com.sun.mail.imap.IMAPSSLProvider
-keep class com.sun.mail.smtp.** {*;}

Using keepclassmembernames for a class tells ProGuard not to obfuscate the class members, but does not have an effect on the class itself. So ProGuard does its job and changes the class name.
So if you want to prevent ProGuard from obfuscating the class name you should use keepnames instead.
To prevent both the obfuscation and shrinking (which is removing in case of not being used), you should use keepclassmembers if you want to target only the class members and keep to target the class itself and its members.

Related

java.lang.ClassNotFoundException raised while the same is shown as loaded in -verbose logs and also present in the OSGI Bundle jar file

I have an existing Maven project working fine on a java version 1.8.0_241. But this supports vaadin version 7.2.6 and is needed to upgrade to vaadin 8 along with the compatibilty package. After making the necessary changes all the compilation issue are resolved but during execution, we are facing a ClassNotFoundException for one of our class GuiBaseApplication. But the class file was present in the OSGI Bundle guibase-2.2.4-SNAPSHOT.jar being used.
This class is an abstract class extending one class and implementing another class.
public abstract class GuiBaseApplication extends UI implements CrumbTrail
{
-
-
}
But when we took the -verbose logs, then could see that class was loaded once as below log.
**[Loaded com.product.rm.common.guibase.GuiBaseApplication from file:/home/user/bcd/com.product.bss.vaadin/target/guibase-2.2.4-SNAPSHOT.jar]**
Uptill now the Web GUI HTTP server was up and running.
Then trying to connect via the browser, the below error was displayed.
HTTP ERROR 500 javax.servlet.ServletException: com.vaadin.server.ServiceException: com.vaadin.server.ServiceException: com.product.rm.common.guibase.GuiBaseApplication could not be loaded
URI: /gui
STATUS: 500
MESSAGE: javax.servlet.ServletException: com.vaadin.server.ServiceException: com.vaadin.server.ServiceException: com.product.rm.common.guibase.GuiBaseApplication could not be loaded
SERVLET: com.product.rm.bcd.server.webgui.ApplicationServlet-27a56cca
CAUSED BY: javax.servlet.ServletException: com.vaadin.server.ServiceException: com.vaadin.server.ServiceException: com.product.rm.common.guibase.GuiBaseApplication could not be loaded
CAUSED BY: com.vaadin.server.ServiceException: com.vaadin.server.ServiceException: com.product.rm.common.guibase.GuiBaseApplication could not be loaded
CAUSED BY: com.vaadin.server.ServiceException: com.product.rm.common.guibase.GuiBaseApplication could not be loaded
CAUSED BY: java.lang.ClassNotFoundException: com.product.rm.common.guibase.GuiBaseApplication
Checking on the existing and working version, we could see that this class is loaded two more times as below but with $1 and $2 sign.
[Loaded com.product.rm.common.guibase.GuiBaseApplication$1 from file:/home/user/bcd/com.product.bss.vaadin/target/guibase-2.2.3-SNAPSHOT.jar]
[Loaded com.product.rm.common.guibase.GuiBaseApplication$2 from file:/home/user/bcd/com.product.bss.vaadin/target/guibase-2.2.3-SNAPSHOT.jar]
We checked and confirmed that these 2 classes are GuiBaseApplication$1 and GuiBaseApplication$2 are present in the guibase-2.2.4-SNAPSHOT.jar file but still class loading issue is there.
It will be very helpful if we get some directions for where to look further. What we can try to identify the cause and then resolve the issue.
it's was a Bug in vaadin check the page
https://floriansblog.wordpress.com/2015/04/30/vaadin-osgi-managing-the-classloader/

NoClassDefFoundError-om/google/api/client/googleapis/batch/json/JsonBatchCallback

I have a static java project and have so many class in it. used jar of java batch,drive Api , mongo Connnection etc and i have no errors compile time but while running a main class i am getting this.what can i do for this ?
Error: Unable to initialize main class kioskdriveCollabMain
Caused by: java.lang.NoClassDefFoundError: com/google/api/client/http/AbstractInputStreamContent
Error: Unable to initialize main class kioskdriveCollabMain
Caused by: java.lang.NoClassDefFoundError: com/google/api/client/googleapis/batch/json/JsonBatchCallback
java.lang.NoClassDefFoundError causes when the dependency isn't resolved i.e. it is unable to find the specified class.
com/google/api/client/http/AbstractInputStreamContent requires google-http-java-client jar.
com/google/api/client/googleapis/batch/json/JsonBatchCallback requires google-api-java-client jar.

Error - Didn't find class "javax.naming.ldap.LdapName"

I'm using unirest to get a camfind result.
The full error log :
04-14 18:24:39.574 1880-2300/projectco.project E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-120
Process: projectco.project, PID: 1880
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/ldap/LdapName;
at com.mashape.relocation.conn.ssl.AbstractVerifier.extractCNs(AbstractVerifier.java:277)
at com.mashape.relocation.conn.ssl.AbstractVerifier.getCNs(AbstractVerifier.java:265)
at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:157)
at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:140)
[...] more "at"s
at bookshotco.bookshot2.MainActivity$1.run(MainActivity.java:100)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.naming.ldap.LdapName" on path: DexPathList[[zip file "/data/app/projectco.project-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
[..]
Suppressed: java.lang.ClassNotFoundException: javax.naming.ldap.LdapName
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 23 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Few people had this problem and even fewer solved it, most of the times using stuff to do with compatibility of different versions which did not work for me.
The emulator I'm using is up to date (nexus 5 on api 21).
I've recently had the same issue and it was only happening in obfuscated code. So keeping the whole org.apache package in Proguard rules solved the issue.
# Keep Apache Package, since it cannot find some of the classes and throws Verify Error
-keep class org.apache.** {*;}
This error can also be caused by requiring ssl (i.e., "useSSL") when connecting to a remote server and NOT having verifyServerCertificate and trustServerCertificate defined as below, and also not having a server certificate defined properly. The system is trying to use an LDAP authentication process, thus the error.
val info = Properties()
info.setProperty("useSSL", "true")
info.setProperty("requireSSL", "true")
info.setProperty("user", user)
info.setProperty("password", password)
info.setProperty("verifyServerCertificate", "false")
info.setProperty("trustServerCertificate", "true")
Also, if you define:
trustServerCertificate=false
then you may need to set the following (unless everything matches up):
disableSslHostnameVerification=true

Errors with Java Applet on web

A java applet that I wrote works exactly as intended when I run it from the code in the applet viewer on my computer. However, when I uploaded it to my website, I get a series of errors. I looked up the errors but can't find any useful information to help figure out the problem. Here are the errors.
java.lang.NoClassDefFoundError: Main
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:678)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassNotFoundException: Main
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 13 more
Exception: java.lang.NoClassDefFoundError: Main
I understand that this might not be descriptive enough without a sample of my code but can anyone discern anything from these errors? Thanks
It simply means the class Main referenced in your code is not included in the applet.
Most likely you did not included the class when exporting to jar.
It'd be great if you included your code, but the problem is likely that you're referencing a class called Main, yet none exists in the CLASSPATH of the service dumping this exception.
You likely need to either create (or rename!) the source to "Main.java" and build a Main.class and put it in the correct path or alter the path to reference where Main.class (or the archive containing Main.class) is stored.

Jars in my grails project not being picked up when deployed to tomcat 5.5

I am running a grails test run-app all day with my application and it is fine. I type "grails prod war" to get a war, and dump it in the webapps folder of my tomcat install. Now i get the message like so:
11.11.2010 16:35:11 *ERROR* GrailsExceptionResolver: Executing action [index] of controller [ResumeController] caused e
xception: java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.jaxb.Context (GrailsExceptionResolver.ja
va, line 72)
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [index] of controll
er [ResumeController] caused exception: java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.jaxb.Cont
ext
at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
at java.lang.Thread.run(Unknown Source)
Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: Could not initialize
class org.docx4j.jaxb.Context
... 3 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.jaxb.Context
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:599)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:199)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:188)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:188)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:169)
at com.iai.skillsdb.DocxHelpers.DocxParser.openDocx4j(DocxParser.java:70)
at ResumeController$_closure8.doCall(ResumeController.groovy:164)
at ResumeController$_closure8.doCall(ResumeController.groovy)
at ResumeController.invokeMethod(ResumeController.groovy)
at ResumeController$_closure1.doCall(ResumeController.groovy:41)
at ResumeController$_closure1.doCall(ResumeController.groovy)
... 3 more
What is causing this? I have the docx4j jar in my WAR for sure, and it is there in the web-inf lib folder as well.
You're getting a java.lang.NoClassDefFoundError, not a java.lang.ClassNotFoundException. The class is being loaded, but a class that it depends on (directly or indirectly via another class) isn't there. You're most likely missing a jar that docx4j requires as a dependency.
Make sure that you have the correct version of docx4j and that there is absolutely no other version of docx4j in your classpath, there may be a version of this lib that did not have the 'Content' class implemented.

Categories