我正在尝试将Leshan Server Demo作为Java库编译到Android Studio中,因为我想将其用于应用程序中。
当我编译它时,我有一个包含的库,该库定义了一个特定的类,该类也由另一个类定义,也包含在项目中。这两个库都是必需的。
这是我的gradle文件
apply plugin: 'java-library'
sourceCompatibility = "8"
targetCompatibility = "8"
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'org.slf4j:slf4j-android:1.7.25'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
implementation 'org.jmdns:jmdns:3.5.5'
implementation 'commons-cli:commons-cli:1.4'
implementation 'org.eclipse.californium:californium-core:2.0.0-M13'
implementation 'org.eclipse.jetty:jetty-webapp:9.4.14.v20181114'
implementation 'org.eclipse.jetty:jetty-continuation:9.4.14.v20181114'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.commons:commons-lang3:3.8.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.eclipse.leshan:leshan-server-cf:1.0.0-M10'
implementation 'org.eclipse.leshan:leshan-server-cluster:1.0.0-M10'
}
源当前与它们的github存储库中的文件相同(上面链接)
如果我尝试编译,我将拥有:
任务:app:transformDexArchiveWithExternalLibsDexMergerForDebug失败
AGPBI:{“种类”:“错误”,“文本”:“程序类型已存在:org.eclipse.leshan.server.cluster.RedisRegistrationStore”,“源”:[{}],“工具”: “ D8”}
据我所知,这意味着两个库正在定义同一类:RedisRegistrationStore
我想做的是以某种方式将其排除。
看这里找到的其他解决方案,例如Similar solution,我试图进行一些排除,并以这种方式修改了gradle文件:
........
implementation 'org.eclipse.leshan:leshan-server-cluster:1.0.0-M10'{
exclude group: 'org.eclipse.leshan', module:'cluster'
}
........
但是也许这意味着我无法进行排除,因为我遇到了另一个错误
找不到类型为org.gradle.api.internal.artifacts类型的对象的参数[build_cbo5jg18zhz8pvdsjliwvve5w $ _run_closure1 $ _closure2 @ 428dc770]的方法org.eclipse.leshan:leshan-server-cluster:1.0.0-M10()。 .dsl.dependencies.DefaultDependencyHandler。
顺便说一句,我不确定排除组/模块是否是解决我的问题的正确方法。我只需要删除一个班。
我也在这里看过:Android doc how to fix duplicate classes
但这不适合我的问题,因为我的类已在lib A和lib B中声明,而不像官方文档中那样直接依赖
您是否对我的案子有一个想法,也许总的来说,解决此问题的最佳方法是什么?
我在做什么错了?
编辑
这是我的依赖树
+--- org.slf4j:slf4j-android:1.7.25
| \--- org.slf4j:slf4j-api:1.7.25
+--- com.fasterxml.jackson.core:jackson-databind:2.9.8
| +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| \--- com.fasterxml.jackson.core:jackson-core:2.9.8
+--- org.jmdns:jmdns:3.5.5
| \--- org.slf4j:slf4j-api:1.7.25
+--- commons-cli:commons-cli:1.4
+--- org.eclipse.californium:californium-core:2.0.0-M13
| +--- org.eclipse.californium:californium-legal:2.0.0-M13
| +--- org.eclipse.californium:element-connector:2.0.0-M13
| | +--- org.eclipse.californium:californium-legal:2.0.0-M13
| | \--- org.slf4j:slf4j-api:1.7.25
| \--- org.slf4j:slf4j-api:1.7.25
+--- org.eclipse.jetty:jetty-webapp:9.4.14.v20181114
| +--- org.eclipse.jetty:jetty-xml:9.4.14.v20181114
| | \--- org.eclipse.jetty:jetty-util:9.4.14.v20181114
| \--- org.eclipse.jetty:jetty-servlet:9.4.14.v20181114
| \--- org.eclipse.jetty:jetty-security:9.4.14.v20181114
| \--- org.eclipse.jetty:jetty-server:9.4.14.v20181114
| +--- javax.servlet:javax.servlet-api:3.1.0
| +--- org.eclipse.jetty:jetty-http:9.4.14.v20181114
| | +--- org.eclipse.jetty:jetty-util:9.4.14.v20181114
| | \--- org.eclipse.jetty:jetty-io:9.4.14.v20181114
| | \--- org.eclipse.jetty:jetty-util:9.4.14.v20181114
| \--- org.eclipse.jetty:jetty-io:9.4.14.v20181114 (*)
+--- org.eclipse.jetty:jetty-continuation:9.4.14.v20181114
+--- commons-io:commons-io:2.6
+--- org.apache.commons:commons-lang3:3.8.1
+--- com.google.code.gson:gson:2.8.5
+--- org.eclipse.leshan:leshan-server-cf:1.0.0-M10
| +--- org.eclipse.leshan:leshan-core-cf:1.0.0-M10
| | +--- org.eclipse.leshan:leshan-core:1.0.0-M10
| | | +--- org.slf4j:slf4j-api:1.7.25
| | | \--- com.eclipsesource.minimal-json:minimal-json:0.9.5
| | +--- org.eclipse.californium:californium-core:2.0.0-M12 -> 2.0.0-M13 (*)
| | \--- org.eclipse.californium:scandium:2.0.0-M12
| | +--- org.eclipse.californium:element-connector:2.0.0-M12 -> 2.0.0-M13 (*)
| | \--- org.slf4j:slf4j-api:1.7.25
| +--- org.eclipse.leshan:leshan-server-core:1.0.0-M10
| | \--- org.eclipse.leshan:leshan-core:1.0.0-M10 (*)
| +--- org.eclipse.californium:californium-core:2.0.0-M12 -> 2.0.0-M13 (*)
| \--- org.eclipse.californium:scandium:2.0.0-M12 (*)
\--- org.eclipse.leshan:leshan-server-cluster:1.0.0-M10
+--- org.eclipse.leshan:leshan-core:1.0.0-M10 (*)
+--- org.eclipse.leshan:leshan-server-cf:1.0.0-M10 (*)
+--- redis.clients:jedis:2.8.0
| \--- org.apache.commons:commons-pool2:2.3
+--- com.eclipsesource.minimal-json:minimal-json:0.9.5
+--- commons-cli:commons-cli:1.3.1 -> 1.4
\--- ch.qos.logback:logback-classic:1.2.3
+--- ch.qos.logback:logback-core:1.2.3
\--- org.slf4j:slf4j-api:1.7.25
答案 0 :(得分:0)
尝试添加此行
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
或者您也可以使用它
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'