Gradle - 类型定义多次,Android - Apache POI 问题
Gradle - Type is defined multiple times, Android - Apache POI problems
我正尝试在 android 上使用 POI。我收到了这个错误。我该如何解决?我可以从依赖项中排除某些东西吗?
Type org.apache.xmlbeans.metadata.system.sXMLCONFIG.TypeSystemHolder is defined multiple times: C:\Users\MSZ\.gradle\caches\transforms-2\files-2.1\cc7d97ae12f5ddeb0f664fc91dcb9489\jetified-xmlbeans-4.0.0.jar:org/apache/xmlbeans/metadata/system/sXMLCONFIG/TypeSystemHolder.class, C:\Users\MSZ\.gradle\caches\transforms-2\files-2.1\cc7d97ae12f5ddeb0f664fc91dcb9489\jetified-xmlbeans-4.0.0.jar:org/apache/xmlbeans/metadata/system/sXMLCONFIG/TypeSystemHolder.class
依赖关系
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.budiyev.android:code-scanner:2.1.0'
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
implementation 'com.google.apis:google-api-services-drive:v3-rev110-1.23.0'
implementation files('libs\commons-collections4-4.4.jar')
implementation files('libs\commons-compress-1.20.jar')
implementation files('libs\poi-5.0.0.jar')
implementation files('libs\poi-ooxml-5.0.0.jar')
implementation files('libs\poi-ooxml-lite-5.0.0.jar')
implementation files('libs\xmlbeans-4.0.0.jar')
implementation 'org.jetbrains:annotations:15.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestimplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
我也可以告诉你,我无法摆脱对 xmlbeans 的依赖,因为我得到了这个异常
java.lang.ClassNotFoundException: Didn't find class "org.apache.xmlbeans.XmlObject" on path: DexPathList[[zip file "/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/lib/arm64, /system/lib64]]
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:171)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at void com.test.scanner.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:55)
at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7224)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7213)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1272)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2926)
at android.app.Activity android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions, android.content.Intent) (ActivityThread.java:3081)
at void android.app.servertransaction.LaunchActivityItem.execute(android.app.ClientTransactionHandler, android.os.IBinder, android.app.servertransaction.PendingTransactionActions) (LaunchActivityItem.java:78)
at void android.app.servertransaction.TransactionExecutor.executeCallbacks(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:108)
at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:68)
at void android.app.ActivityThread$H.handleMessage(a`ndroid.os.Message) (ActivityThread.java:1831)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
at void android.os.Looper.loop() (Looper.java:201)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6810)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:873)
I/.barcodescanne: Rejecting re-init on previously-failed class java.lang.Class<org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook>: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/xmlbeans/XmlObject;
at void com.test.scanner.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:55)
at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7224)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7213)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1272)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2926)
at android.app.Activity android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions, android.content.Intent) (ActivityThread.java:3081)
at void android.app.servertransaction.LaunchActivityItem.execute(android.app.ClientTransactionHandler, android.os.IBinder, android.app.servertransaction.PendingTransactionActions) (LaunchActivityItem.java:78)
at void android.app.servertransaction.TransactionExecutor.executeCallbacks(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:108)
at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:68)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1831)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
at void android.os.Looper.loop() (Looper.java:201)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6810)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:873)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.xmlbeans.XmlObject" on path: DexPathList[[zip file "/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/lib/arm64, /system/lib64]]
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:171)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at void com.test.scanner.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:55)
at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7224)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7213)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1272)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2926)
at android.app.Activity android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions, android.content.Intent) (ActivityThread.java:3081)
at void android.app.servertransaction.LaunchActivityItem.execute(android.app.ClientTransactionHandler, android.os.IBinder, android.app.servertransaction.PendingTransactionActions) (LaunchActivityItem.java:78)
at void android.app.servertransaction.TransactionExecutor.executeCallbacks(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:108)
at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:68)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1831)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
at void android.os.Looper.loop() (Looper.java:201)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6810)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:873)
我尝试清理并重建项目,但没有成功。我在桌面应用程序中测试了 POI。它与这些 jar 库完美配合。
谢谢!
好的,我解决了。 POI 在 android 上有问题。它有效,我下载并添加了这两个 jar 以构建路径:
- poi-3.12-android-a.jar
- poi-ooxml-schemas-3.12-20150511-a.jar
下载link:
我正尝试在 android 上使用 POI。我收到了这个错误。我该如何解决?我可以从依赖项中排除某些东西吗?
Type org.apache.xmlbeans.metadata.system.sXMLCONFIG.TypeSystemHolder is defined multiple times: C:\Users\MSZ\.gradle\caches\transforms-2\files-2.1\cc7d97ae12f5ddeb0f664fc91dcb9489\jetified-xmlbeans-4.0.0.jar:org/apache/xmlbeans/metadata/system/sXMLCONFIG/TypeSystemHolder.class, C:\Users\MSZ\.gradle\caches\transforms-2\files-2.1\cc7d97ae12f5ddeb0f664fc91dcb9489\jetified-xmlbeans-4.0.0.jar:org/apache/xmlbeans/metadata/system/sXMLCONFIG/TypeSystemHolder.class
依赖关系
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.budiyev.android:code-scanner:2.1.0'
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
implementation 'com.google.apis:google-api-services-drive:v3-rev110-1.23.0'
implementation files('libs\commons-collections4-4.4.jar')
implementation files('libs\commons-compress-1.20.jar')
implementation files('libs\poi-5.0.0.jar')
implementation files('libs\poi-ooxml-5.0.0.jar')
implementation files('libs\poi-ooxml-lite-5.0.0.jar')
implementation files('libs\xmlbeans-4.0.0.jar')
implementation 'org.jetbrains:annotations:15.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestimplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
我也可以告诉你,我无法摆脱对 xmlbeans 的依赖,因为我得到了这个异常
java.lang.ClassNotFoundException: Didn't find class "org.apache.xmlbeans.XmlObject" on path: DexPathList[[zip file "/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/lib/arm64, /system/lib64]]
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:171)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at void com.test.scanner.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:55)
at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7224)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7213)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1272)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2926)
at android.app.Activity android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions, android.content.Intent) (ActivityThread.java:3081)
at void android.app.servertransaction.LaunchActivityItem.execute(android.app.ClientTransactionHandler, android.os.IBinder, android.app.servertransaction.PendingTransactionActions) (LaunchActivityItem.java:78)
at void android.app.servertransaction.TransactionExecutor.executeCallbacks(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:108)
at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:68)
at void android.app.ActivityThread$H.handleMessage(a`ndroid.os.Message) (ActivityThread.java:1831)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
at void android.os.Looper.loop() (Looper.java:201)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6810)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:873)
I/.barcodescanne: Rejecting re-init on previously-failed class java.lang.Class<org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook>: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/xmlbeans/XmlObject;
at void com.test.scanner.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:55)
at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7224)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7213)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1272)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2926)
at android.app.Activity android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions, android.content.Intent) (ActivityThread.java:3081)
at void android.app.servertransaction.LaunchActivityItem.execute(android.app.ClientTransactionHandler, android.os.IBinder, android.app.servertransaction.PendingTransactionActions) (LaunchActivityItem.java:78)
at void android.app.servertransaction.TransactionExecutor.executeCallbacks(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:108)
at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:68)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1831)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
at void android.os.Looper.loop() (Looper.java:201)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6810)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:873)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.xmlbeans.XmlObject" on path: DexPathList[[zip file "/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.scanner-tO5vSzAMf2TMgMjcFMuIJg==/lib/arm64, /system/lib64]]
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:171)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at void com.test.scanner.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:55)
at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7224)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7213)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1272)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2926)
at android.app.Activity android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions, android.content.Intent) (ActivityThread.java:3081)
at void android.app.servertransaction.LaunchActivityItem.execute(android.app.ClientTransactionHandler, android.os.IBinder, android.app.servertransaction.PendingTransactionActions) (LaunchActivityItem.java:78)
at void android.app.servertransaction.TransactionExecutor.executeCallbacks(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:108)
at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:68)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1831)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
at void android.os.Looper.loop() (Looper.java:201)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6810)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:873)
我尝试清理并重建项目,但没有成功。我在桌面应用程序中测试了 POI。它与这些 jar 库完美配合。
谢谢!
好的,我解决了。 POI 在 android 上有问题。它有效,我下载并添加了这两个 jar 以构建路径:
- poi-3.12-android-a.jar
- poi-ooxml-schemas-3.12-20150511-a.jar
下载link: