本文介绍了“无法合并dex";使用房间时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为项目添加一个房间".

I'm trying to add a "room" to my project.

当我尝试构建项目时,出现错误:

When I try to build a project, I get an error:

我已经完成的事情:

  1. 清洁/重建项目
  2. 我在defaultConfig {}中添加了"multiDexEnabled true".然后我得到错误:
  1. Clean/Rebuild project
  2. I added "multiDexEnabled true" in defaultConfig{}. Then I get the error:

如果我从项目中删除房间",则它的构建没有错误.

If I remove the "room" from my project, it is build without errors.

我正在使用Android Studio 3 gradle构建工具3.0.0.

I'm using Android Studio 3, gradle build tools 3.0.0.

这是我的build.gradle:

This is my build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

buildscript {
   repositories {
       mavenCentral()
   }

   dependencies {
       classpath 'me.tatarka:gradle-retrolambda:3.2.5'
   }
}

repositories {
    mavenCentral()
}

android {
   compileSdkVersion 23
   buildToolsVersion '26.0.2'

   defaultConfig {
        applicationId "trsnet.gtp2.com"
        minSdkVersion 17
        targetSdkVersion 23
        multiDexEnabled true
   }

   buildTypes {
       release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.txt'
       }
   }

   compileOptions {
       sourceCompatibility JavaVersion.VERSION_1_8
       targetCompatibility JavaVersion.VERSION_1_8
   }

}

dependencies {

    compile files('libs/commons-codec-1.9.jar')
    compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-
    dependencies.jar')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:23.2.1'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support.constraint:constraint-layout:+'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
    implementation 'android.arch.persistence.room:runtime:1.0.0'
    annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
}

推荐答案

我也遇到了这个问题,我花了相当长的时间才能解决,但是我终于明白了. ROOM使用了一些support-v4库,因此这就是为什么您会收到错误的zip条目的错误的原因.在我的情况下,ROOM使用的是比我需要的要早的版本的组件.所以对我有用的是(在此处找到)正在将以下内容添加到Gradle文件的根级别:

I was having this problem too and it took me quite a while to solve, but I finally got it. ROOM uses some of the support-v4 libraries so this is why you are getting the error that there are duplicate zip entries. In my situation, ROOM is using components from an earlier version than what I needed. So what worked for me (found here) is adding the following to the root level of the Gradle file:

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

我发现这是因为它阻止了库包含任何support-v4组件,但是随后您必须手动包括ROOM和其他可能需要的组件.如果您需要确切找出哪些库是重复的,则可以遵循这些说明以了解每个库及其依赖项.

What I found this does is it prevents libraries from including any support-v4 components, but then you have to manually include the necessary components for both ROOM and anything else you might need. If you need to find out exactly which libraries are duplicates then you can follow these instructions to look into each library and it's dependencies.

稍微不相关的注释:从使用compile配置的Gradle 3.0起,已弃用,应将其替换为implementationapi,可以找到很好的解释.

Slightly unrelated note: As of Gradle 3.0 using the compile configuration is deprecated and should be replace with implementation or api, a nice explanation can be found here.

这篇关于“无法合并dex";使用房间时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:38