gpt4 book ai didi

android - 在 Room 持久性上构建版本时出现错误 [DuplicatePlatformClasses] 类冲突

转载 作者:太空宇宙 更新时间:2023-11-03 11:46:43 25 4
gpt4 key购买 nike

我已使用本指南在我的 Android 应用程序中使用 Room 构建持久性: https://developer.android.com/training/data-storage/room/index.html

并添加了如下所示的依赖项: https://developer.android.com/topic/libraries/architecture/adding-components.html

当我构建调试版本并部署到手机时,一切正常。

当我构建发布签名的 APK 时,我收到此错误消息:

Error:Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]

我的应用程序.gradle:

apply plugin: 'com.android.application'

android {
signingConfigs {
/* TODO(developer): Configure to sign app with a release key for testing.
release {
storeFile file('path/to/release/signing/key')
keyAlias 'release_key_alias'
keyPassword "${password}"
storePassword "${password}"
}*/
}
compileSdkVersion 26
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "myappid"
minSdkVersion 14
targetSdkVersion 23
versionCode 10
versionName "1.8"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// TODO(developer): uncomment below once config above is complete and uncommented.
//signingConfig signingConfigs.release

}
}
}
configurations {
all {
exclude module: 'httpclient'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.1.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.github.nkzawa:socket.io-client:0.3.0'
compile 'io.socket:socket.io-client:0.8.3'
compile 'com.android.support:design:26.1.0'
compile 'android.arch.persistence.room:runtime:1.0.0'
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}

我的项目.gradle

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'io.socket:socket.io-client:0.8.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext{
roomVersion = '1.0.0'
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}

有人可以帮助我或给我线索吗?

最佳答案

我终于发现问题出在一个 JSON 子模块上:

compile 'com.github.nkzawa:socket.io-client:0.3.0'

这个库有一个子模块:

org.json:json

现在与 android native 模块冲突,因为在我的其他依赖项中我找不到这个。 10天前它工作正常。我也不得不杀了这个:

compile 'io.socket:socket.io-client:0.8.3'

最终的解决方案是为模块添加一个排除项并像这样更改行:

    implementation ('com.github.nkzawa:socket.io-client:0.3.0',{
exclude group:'org.json', module:'json'
})

我还注意到,在我解决了问题之后,错误日志中提示我存在冲突的模块,但即使我阅读了一百遍,我之前也没有注意到: enter image description here

所以也许谷歌或 Intellij 可以改进这个错误的编写......

要发现此类重复冲突错误模块,我发现最好的方法是创建一个新项目并粘贴到应用程序 build.gradle 中的依赖项,并逐一检查它们或使用“dividi et impera”,也许这对某人来说是一个明显的建议,但我希望早点得到它。

关于android - 在 Room 持久性上构建版本时出现错误 [DuplicatePlatformClasses] 类冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47337218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com