2017-07-14 66 views
1

我有以下的依存关系:Android的摇篮失败多DEX文件定义okhttp

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.squareup.retrofit2:retrofit:2.3.0' 
    compile 'com.squareup.retrofit2:converter-moshi:2.3.0' 
    compile('com.github.eoinsha:JavaPhoenixChannels:0.2') { 
     exclude module: 'groovy-all' 
    } 
} 

而下面的依赖关系树:

+--- com.android.support:appcompat-v7:25.3.1 
| +--- com.android.support:support-annotations:25.3.1 
| +--- com.android.support:support-v4:25.3.1 
| | +--- com.android.support:support-compat:25.3.1 
| | | \--- com.android.support:support-annotations:25.3.1 
| | +--- com.android.support:support-media-compat:25.3.1 
| | | +--- com.android.support:support-annotations:25.3.1 
| | | \--- com.android.support:support-compat:25.3.1 (*) 
| | +--- com.android.support:support-core-utils:25.3.1 
| | | +--- com.android.support:support-annotations:25.3.1 
| | | \--- com.android.support:support-compat:25.3.1 (*) 
| | +--- com.android.support:support-core-ui:25.3.1 
| | | +--- com.android.support:support-annotations:25.3.1 
| | | \--- com.android.support:support-compat:25.3.1 (*) 
| | \--- com.android.support:support-fragment:25.3.1 
| |   +--- com.android.support:support-compat:25.3.1 (*) 
| |   +--- com.android.support:support-media-compat:25.3.1 (*) 
| |   +--- com.android.support:support-core-ui:25.3.1 (*) 
| |   \--- com.android.support:support-core-utils:25.3.1 (*) 
| +--- com.android.support:support-vector-drawable:25.3.1 
| | +--- com.android.support:support-annotations:25.3.1 
| | \--- com.android.support:support-compat:25.3.1 (*) 
| \--- com.android.support:animated-vector-drawable:25.3.1 
|   \--- com.android.support:support-vector-drawable:25.3.1 (*) 
+--- com.squareup.retrofit2:retrofit:2.3.0 
| \--- com.squareup.okhttp3:okhttp:3.8.0 
|   \--- com.squareup.okio:okio:1.13.0 
+--- com.squareup.retrofit2:converter-moshi:2.3.0 
| +--- com.squareup.retrofit2:retrofit:2.3.0 (*) 
| \--- com.squareup.moshi:moshi:1.4.0 
|   \--- com.squareup.okio:okio:1.11.0 -> 1.13.0 
\--- com.github.eoinsha:JavaPhoenixChannels:0.2 
    +--- com.fasterxml.jackson.core:jackson-databind:2.8.3 
    | +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0 
    | \--- com.fasterxml.jackson.core:jackson-core:2.8.3 
    \--- com.squareup.okhttp3:okhttp-ws:3.4.1 
      \--- com.squareup.okhttp3:okhttp:3.4.1 -> 3.8.0 (*) 

而试图建立的项目中,我得到这个错误:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. 
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lokhttp3/internal/ws/WebSocketReader$FrameCallback; 

这应该是由两个不同版本的okhttp库在classpath:

  • 3.4.1 com.squareup.okhttp3:okhttp-ws这是改造的JavaPhoenixChannels

  • 3.8.0依赖

摇篮应该能够自动解决这个问题,所以我想知道什么是问题。 我试图通过排除okhttpokhttp-ws来解决它们各自的第一类依赖问题,并单独编译它们,但这似乎没有帮助。

为什么会弹出这样的错误的一些解释也赞赏。

+0

你在应用的build.gradle文件中添加defaultConfig {multiDexEnabled真}模块?然后清理该项目并尝试再次构建。 –

+0

@RohitPadma这似乎不相干。我没有遇到方法限制问题。 – DarthPaghius

+0

https://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility/21100040 –

回答

1

正如评论所指出的@Selvin,该问题是由事实okhtt-ws已经核心项目中,因为3.5版本的移动,因此指定okhttp和两个较新版本的旧版本的okhttp-ws会引起导致两个不同的okhttp-ws库副本在类路径上结束。对于gradle,这些将会是使用相同包层次结构的不同库,因此它不会自动排除一个库。

TL; DR错误是由不包括okhttp-ws的依赖,因为它是在okhttp本身的3.8版本已经可以固定:

compile 'com.squareup.okhttp3:okhttp:3.8.0' 
compile('com.github.eoinsha:JavaPhoenixChannels:0.2') { 
    exclude module: 'okhttp-ws' 
}