微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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”检查它们,也许这是一个对某人的明显建议,但我希望能早点得到它.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐