android – 在Room persistence上构建版本时出错[DuplicatePlatformClasses]类冲突

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

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

当我构建调试版本和沉到手机,everithing工作正常.

当我构建发布签名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' }
    }
}

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

解决方法:

我终于发现问题是一个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'

最后的解决方案是为模块添加一个排除,并改变这样的行:

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

我也注意到我解决了问题,在错误日志中,它建议我冲突的模块,但即使我读了一百次,我之前没有注意到:

enter image description here

所以也许google或Intellij可以改善这个错误的写作……

要发现这个类重复冲突错误模块,我发现最好的方法是创建一个新项目并粘贴到app build.gradle中的dependancies,然后逐个或“dividi et impera”检查它们,也许这是一个对某人的明显建议,但我希望能早点得到它.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...