如何解决不同版本的相同jar中的重复类-Android
当同步成功完成时,我正在尝试将iText集成到我的Android Studio项目中。
然后,我写了一些代码,并尝试构建并测试它,当它给出一个错误(一个巨大的错误)时,即在不同版本的同一jar中发现了重复的类。 (我删除了一些,因为有很多)
Duplicate class com.keypoint.PngEncoder found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Duplicate class org.jfree.JCommon found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Duplicate class org.jfree.JCommonInfo found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Duplicate class org.jfree.base.AbstractBoot found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Duplicate class org.jfree.base.BaseBoot found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Duplicate class org.jfree.base.BasicProjectInfo found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
...
Duplicate class org.jfree.base.BasicProjectInfo$OptionalLibraryHolder found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Duplicate class org.jfree.base.BootableProjectInfo found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Duplicate class org.jfree.util.WaitingImageObserver found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
Go to the documentation to learn how to Fix dependency resolution errors.
据此,我了解到同一罐子的不同版本导致了此问题。因此,我尝试删除版本较低的版本(jcommon-1.0.15和1个其他版本),但是当我使用gradle同步项目时,它再次下载了它们,如果我离线运行它,则表示无法解决依赖项。更高版本的罐子也是如此。
更新:
以下是我要求的build.gradle
文件:
项目级别:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用级别:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.nalin.app"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs',include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.activity:activity:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':libraries:OpenCV')
implementation 'itext:itext:4.2.1'
}
我也包含了OpenCV,所以这里是OpenCV的gradle文件:
apply plugin: 'com.android.library'
buildscript {
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 2480
versionName "2.4.8"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
解决方法
感谢评论中的家伙,我可以很轻松地解决问题。
我所做的是运行gradlew app:dependencies
,它给了我一棵依赖树。
从那棵树中,我可以找出该库的哪些部分需要哪些可传递依赖关系,并且我使用以下方法排除了没有任何其他依赖关系的较低版本的jcommon库:exclude group: 'jfree',module: 'jcommon'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。