Gradle - 多次定义类型,Android - Apache POI问题
Posted
技术标签:
【中文标题】Gradle - 多次定义类型,Android - Apache POI问题【英文标题】:Gradle - Type is defined multiple times, Android - Apache POI problems 【发布时间】:2021-09-30 09:36:55 【问题描述】:我正在尝试在 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 库完美配合。
谢谢!
【问题讨论】:
【参考方案1】:好的,我解决了。 POI在android上有问题。它可以工作,我下载并添加了这两个 jar 来构建路径:
-
poi-3.12-android-a.jar
poi-ooxml-schemas-3.12-20150511-a.jar
下载链接:
https://github.com/andruhon/android5xlsx
【讨论】:
以上是关于Gradle - 多次定义类型,Android - Apache POI问题的主要内容,如果未能解决你的问题,请参考以下文章
Android Gradle 插件自定义 Gradle 插件模块 ① ( 在 Module 模块中自定义 Gradle 插件 | 创建自定义插件类型模块 | 手动导入相关依赖 )
Android Gradle 插件将自定义 Gradle 插件上传到远程仓库中 ① ( 在 Module 模块中自定义 Gradle 插件 | 创建自定义插件类型模块 | 手动导入相关依赖 )