How to prevent a missed unused annotation class from crashing my program?

I want to use a class from a third-party library that is annotated using @XmlRootElement from javax.xml.bind.annotation . This annotation does not exist on Android and is difficult to add (as in a secure namespace).

I don't actually use the class in the context of JAXB, so I'm more than happy to ignore the annotation. The Android JVM, however, is not and throws a ClassNotFounException from the class loader:

  Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlAccessorType in loader dalvik.system.PathClassLoader[/data/app/csiro.truststore.client.tssandroidclient-2.apk] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251) at java.lang.ClassLoader.loadClass(ClassLoader.java:540) at java.lang.ClassLoader.loadClass(ClassLoad 

Is there a way to get Android to ignore annotation?

+4
source share
1 answer

I don't know a way to ignore it, but Proguard will remove annotations during obfuscation. Usually you do not obfuscate the development assembly, but you can set up the obfuscation process to ignore all classes and thus remove annotations.

+2
source

Source: https://habr.com/ru/post/1400296/


All Articles