简体   繁体   English

Intellij:避免“已定义多个Dex文件”

[英]Intellij: Avoiding 'Multiple Dex Files Defined'

Problem: 问题:

Up until now I've been using Gradle to handle all of my dependencies, and it seems to take care of any duplicate dependencies between other Gradle modules. 到目前为止,我一直在使用Gradle处理我的所有依赖关系,并且似乎可以处理其他Gradle模块之间的所有重复依赖关系。 However, this does not seem to be the case when a duplicate dependency exists within a jar. 但是,当jar中存在重复的依赖项时,情况似乎并非如此。

Question: 题:

Considering that I have control over what goes into the jar, What is the best practices for handling these dependency conflicts using Gradle: 考虑到我可以控制jar中的内容,使用Gradle处理这些依赖项冲突的最佳实践是什么:

  1. Do not include any external dependencies in the jar, include them in the project itself using build.gradle 不要在jar中包含任何外部依赖项,请使用build.gradle将其包含在项目本身中

  2. Include all external dependcies in the jar, remove duplicates as they occur by removing them from the project build.gradle . 将所有外部依赖项包含在jar中,通过从项目build.gradle其删除,以消除重复build.gradle ( NOTE: this does not seem scalable, eg if there are duplicates between jars themselves.) 注意:这似乎不可扩展,例如,如果罐子本身之间存在重复项。)

  3. Something better (that hopefully handles this automatically) 更好的东西(希望可以自动处理)

EDIT: build.gradle file: 编辑: build.gradle文件:

apply plugin: 'com.android.application'

android {
    signingConfigs {
        release { ... }
        debug { ... }
    }
    compileSdkVersion 19
    buildToolsVersion '19.1.0'
    defaultConfig { ... }
    buildTypes {
        release { ... }
        debug { ... }
    } 
    sourceSets {
        instrumentTest.setRoot('tests')
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:20.0.0'
    compile project(':jarModule')
}

When importing external jars that have a dependency that you also have in your local app, you can do two things: 导入具有本地应用程序中也具有依赖性的外部jars ,您可以执行以下两项操作:

Convert your jar dependency to a Gradle dependency and exclude the dependency jar依赖项转换为Gradle依赖项,并排除依赖项

For example: 例如:

testCompile('org.robospock:robospock:0.5.0')  {
     exclude module: "groovy-all" // <-- excludes groovy from robo spock
}

or 要么

Remove the local dependency in your app and rely on the one in the .jar 在您的应用中删除本地依赖项,并依靠.jar依赖项

For example, in your case with Gson : 例如,对于您与Gson的情况:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:20.0.0'
    compile project(':jarModule')
    // compile 'com.google.code.gson:gson:2.3.1' // <-- removed
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 转换为Dalvik格式失败:无法执行dex:定义了多个dex文件 - Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files are defined TransformException多个dex文件 - TransformException multiple dex files 无法执行dex:多个dex文件已定义 - Unable to execute dex: Multiple dex files define 无法执行dex:定义了多个dex文件…或NoClassDefFoundError - Unable to execute dex: Multiple dex files define… OR NoClassDefFoundError Eclipse / Java / Android无法执行dex:定义了多个dex文件 - Eclipse/Java/Android Unable to execute dex: Multiple dex files define 多个dex文件 - 转换为Dalvik格式失败 - 无法执行dex - Multiple dex files - Conversion to Dalvik format failed - Unable to execute dex Android Socialize SDK:无法执行dex:多个dex文件定义 - Android Socialize SDK: Unable to execute dex: Multiple dex files define 无法执行 dex:多个 dex 文件定义了 Lbolts/AggregateException - Unable to execute dex: Multiple dex files define Lbolts/AggregateException Android多个dex文件定义问题 - Android Multiple dex files define issue 将字节码转换为dex:原因:com.android.dex.DexException:定义了多个dex文件 - converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM