centic9 / poi-on-android

A sample project that shows how Apache POI can be used in an Android application
Apache License 2.0
357 stars 89 forks source link

Unexpected reference to missing service class #109

Closed Basheer009 closed 7 months ago

Basheer009 commented 1 year ago

I got this when building APK

Unexpected reference to missing service class: META-INF/services/javax.xml.stream.XMLEventFactory. Unexpected reference to missing service class: META-INF/services/javax.xml.stream.XMLInputFactory. Unexpected reference to missing service class: META-INF/services/javax.xml.stream.XMLOutputFactory.

centic9 commented 1 year ago

With "building APK", you mean the test-app that is included in this project, right?

Which version of JDK are you using?

Any local changes?

Do you have the system properties in place that are described at https://github.com/centic9/poi-on-android#necessary-system-properties.

And please provide the full output if there is more.

Basheer009 commented 1 year ago

Sorry for late reply, Building APK I mean creating a release, minifyEnabled true and I have applied the proguard-rules.pro config as described in this repo

My JDK is 11.0.16 and Yes I have added the system properties like this:

System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl"); System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl"); System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl");

in my App class which extends Application

Task :app:minifyReleaseWithR8 AGPBI: {"kind":"warning","text":"Unexpected reference to missing service class: META-INF/services/javax.xml.stream.XMLEventFactory.","sources":[{"file":"C:\AndroidProjects\CIDApp\app\build\intermediates\merged_java_res\release\base.jar"}],"tool":"R8"} AGPBI: {"kind":"warning","text":"Unexpected reference to missing service class: META-INF/services/javax.xml.stream.XMLInputFactory.","sources":[{"file":"C:\AndroidProjects\CIDApp\app\build\intermediates\merged_java_res\release\base.jar"}],"tool":"R8"} AGPBI: {"kind":"warning","text":"Unexpected reference to missing service class: META-INF/services/javax.xml.stream.XMLOutputFactory.","sources":[{"file":"C:\AndroidProjects\CIDApp\app\build\intermediates\merged_java_res\release\base.jar"}],"tool":"R8"}

EliAgne commented 7 months ago

Could you provide the MainActivity or app java, build gradle and proguard files? It's difficult to determine the issue with the information given.

Basheer009 commented 7 months ago

in my proguard file:

`# for excel use

Apache POI

-dontwarn org.apache. -dontwarn org.openxmlformats.schemas. -dontwarn org.etsi. -dontwarn org.w3. -dontwarn com.microsoft.schemas. -dontwarn com.graphbuilder. -dontwarn javax.naming. -dontwarn java.lang.management. -dontwarn org.slf4j.impl. -dontwarn java.awt. -dontwarn net.sf.saxon. -dontwarn org.apache.batik. -dontwarn org.apache.logging.log4j.**

-dontnote org.apache. -dontnote org.openxmlformats.schemas. -dontnote org.etsi. -dontnote org.w3. -dontnote com.microsoft.schemas. -dontnote com.graphbuilder. -dontnote javax.naming. -dontnote java.lang.management. -dontnote org.slf4j.impl.**

-keeppackagenames org.apache.poi.ss.formula.function

-keep,allowoptimization,allowobfuscation class org.apache.logging.log4j. { *; } -keep,allowoptimization class org.apache.commons.compress.archivers.zip.* { ; } -keep,allowoptimization class org.apache.poi.schemas. { *; } -keep,allowoptimization class org.apache.xmlbeans. { *; } -keep,allowoptimization class org.openxmlformats.schemas.* { ; } -keep,allowoptimization class com.microsoft.schemas. { *; } `

my app java file at onCreate

System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl"); System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl"); System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl");

This what i get when building release app Screenshot 2024-04-08 004342

centic9 commented 7 months ago

These are just warnings, right?

Is anything not working because of this or are you just curious about the warnings?

Android is missing some parts of normal JDK, this is why the setProperty()-calls are necessasry, the warnings might be remnants of this and may be hard to avoid here.

centic9 commented 7 months ago

I have now excluded those files from the poi-shadow-all.jar to remove the warning.