在Room persistence上构建版本时,错误[DuplicatePlatformClasses]类发生冲突

Rom*_*meo 4 android gradle android-manifest android-gradle-plugin android-room

我已经使用本指南在我的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]
Run Code Online (Sandbox Code Playgroud)

我的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"
}
Run Code Online (Sandbox Code Playgroud)

我的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' }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

Rom*_*meo 11

我终于发现问题是一个JSON子模块:

compile 'com.github.nkzawa:socket.io-client:0.3.0'
Run Code Online (Sandbox Code Playgroud)

这个库有一个子模块:

org.json:json
Run Code Online (Sandbox Code Playgroud)

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

compile 'io.socket:socket.io-client:0.8.3'
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

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