当前位置: 首页 > 知识库问答 >
问题:

在Room持久性上构建发布时出错[DuplicatePlatformClass]类冲突

艾茂学
2023-03-14

我用这个指南在我的Android应用程序中构建了持久性: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]

我的app.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"
}

我的project.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' }
    }
}

有人能帮忙或者给我线索吗?

共有3个答案

广献
2023-03-14

如何找到复制库。

打开gradle run窗口并运行以下命令:

gradle module-name:dependencies

“模块名”应该是你的应用程序模块名,对我来说是“osmunda demo”。

然后使用Ctrl F搜索“commons logging”,您将找到它。

林承悦
2023-03-14

我也有同样的问题,我通过gradle依赖树搜索冲突:

gradlew app:dependencies

然后我排除了冲突库的json模块:

implementation ('<conflicting-library>',{
     exclude group:'org.json', module:'json'
})
桑思远
2023-03-14

我最终发现问题出在JSON子模块上:

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

这个库有一个子模块:

org.json:json

这现在与android原生模块冲突,因为在我的其他依赖项中我找不到这个。10天前它运行良好。我还必须杀死这个:

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

最终的解决方案是为模块添加一个exclude,并更改行,如下所示:

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

所以也许谷歌或Intellij可以改进这些错误的书写。。。

要发现这个类重复冲突错误模块,我发现最好的方法是创建一个新项目并粘贴在应用程序build.gradle中的依赖项,并逐个检查它们或使用“分立等”,也许这是一个明显的建议某人,但我想早点拥有它。

 类似资料:
  • 下面是Kotlin中的类: 但当我试图运行应用程序时,它立即崩溃。以下是崩溃日志: 类似乎不是自动生成的。我检查了从codelab下载的原始java应用程序,发现是自动生成的。

  • 我想在运行时生成的SQLite数据库上运行查询(而不是@Dao中的标准compiletime查询)。例如,我可能想在SQLite数据库中搜索一个文本列,看看它是否包含N个长度的列表中的所有单词。在原始SQLITE中,N为3的查询如下所示: 我尝试过生成并传递查询的结尾,而不是仅仅传递变量。例如: 在@Dao中: 这似乎对我不起作用。你知道如何让运行时生成的查询与Room一起工作吗? 附言:

  • 我试图通过新的android room库更新我的数据库,但它不起作用。这就是我的方法 主要活动。JAVA CarViewModel。JAVA 卡ao.java 我做了调试,新数据出现并调用viewModel。updateItems(list)方法。提前谢谢!

  • 我正在使用android的房间持久性库,如果有人能帮助我使用外键,如何通过使用外键获取数据,我将不胜感激。

  • 当我运行程序时。我在我的LogCat中得到“Migration Ended”日志,但当我再次尝试access数据库时,它给我以下错误。 我完全不知道这个“整数”要到哪里去。我尝试了卸载,使缓存无效和任何其他密切相关的解决方案。知道这是怎么回事吗?如果你刚安装应用程序,它的工作非常好。只有在迁移后才会出现错误。根据我的日志猫,所有迁移步骤似乎都已完成,但仍然显示迁移没有正确处理。

  • 我想在heroku上有一个tilestream,我遵循了教程,我做了完全相同的事情,并不断得到一个构建/编译错误。 刚刚添加了2个文件和一个目录: Procfile: 包裹json: 空的/平铺方向。 当通过git推送到heroku时,我得到以下错误: 当我去网站时,我得到了错误(检查这里) 我还检查了日志: 以及在heroku上运行的进程: 对于这个例子,我没有将地图上传到./ware目录,但是