I have created a java library to be used in an android project. Since I needed my jar to produce log statements, I went for log4j implementation which works fine in my project. But when the project is archived and used in an android project, it throws the below error:
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.beans.Introspector" on path: DexPathList[[zip file "/data/app/com.heb.paxpayapp-yDktv3EaH6Ky6U6ANLZU3A==/base.apk"],nativeLibraryDirectories=[/data/app/com.heb.paxpayapp-yDktv3EaH6Ky6U6ANLZU3A==/lib/x86_64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at org.apache.log4j.config.PropertySetter.setProperty(PropertySetter.java:155)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:130)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:97)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:684)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:367)
at com.heb.driver.PaymentDriver.<init>(PaymentDriver.java:93)
This is because of the below code:
Properties props = new Properties();
props.load(getClass().getResourceAsStream("/resources/log4j.properties"));
PropertyConfigurator.configure(props);
- What should be logging framework and the dependencies to be used in this case?
- Seeing that PropertyConfigurator.configure(props) doesn't work in Android due to beans dependency. What would be an alternate solution to load log4j properties. Should I be creating java configuration for SimpleLayout, FileAppenders to load the log4j properties dynamically?
Please share your thoughts. Any examples would be very helpful.