Jor*_*sys 12 java android gradle android-studio
使用“ Cxense SDK for Android”,我收到重复类的消息:
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (**com.android.support:support-compat:27.1.1**) and classes.jar (**com.android.support:support-v4:22.2.0**)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (com.android.support:support-compat:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (com.android.support:support-compat:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.ListFragment found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.ListFragment$1 found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.ListFragment$2 found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.LoaderManager found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Run Code Online (Sandbox Code Playgroud)
这是我的应用级build.gradle配置:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.tototita.cxensetestapp"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//**CXsense
implementation 'com.cxpublic:cxense-android:1.0.1'
}
Run Code Online (Sandbox Code Playgroud)
如何避免 Cxense SDK 中肯定包含的重复类?
Jee*_*ede 22
有两种方法可以解决您的问题。
排除重复的依赖,而implementation 独立,
以通用方式从每个s 中排除重复的依赖项。implementation
在这里,在您的情况下,工件com.android.support是重复的,因为您的应用程序模块使用版本 : 27.1.1而您的工件com.cxpublic:cxense-android:1.0.1具有com.android.support使用版本的内部依赖性:22.2.0。
因此,您应该手动删除其中之一(建议删除旧版本或较低版本)。让我们尝试删除它!
通过第一种方法:
implementation ('com.cxpublic:cxense-android:1.0.1') {
exclude group: "com.android.support", module: "support-v4"
}
Run Code Online (Sandbox Code Playgroud)
当我们在这个工件上使用我们的实现时,将exclude for group com.android.support放在我们的工件中com.cxpublic:cxense-android:1.0.1不会被导入到support-v4库中。
因此,问题将通过手动将此块放置到每个具有此冲突的工件来解决。
第二种方式:
我们可以删除包含的依赖项,并用一个最新编号的包替换它们。在我们的例子中,它support-v4具有不同的版本。因此,转到应用程序级别build.gradle的 android 块并将块放在那里以support-v4从所有工件中删除重复项,以便我们可以有不同的依赖项。
android {
// Some other stuffs
configurations {
all*.exclude module: 'support-v4' // This removes all other versions of `support-v4` if gets duplicated from all the artifacts.
}
// Rest of other stuffs
}
Run Code Online (Sandbox Code Playgroud)
小智 14
如果有重复,请使用exclude:
implementation ('com.cxpublic:cxense-android:1.0.1') {
exclude group: "com.android.support", module: "support-v4"
}
Run Code Online (Sandbox Code Playgroud)
或删除implementation 'com.android.support:appcompat-v7:27.1.1'以支持support-v4.
参见:https : //discuss.gradle.org/t/how-do-i-exclude-specific-transitive-dependencies-of-something-i-depend-on/17991
| 归档时间: |
|
| 查看次数: |
23193 次 |
| 最近记录: |