2

我有一个相当大的android项目。该项目仍然可以编译,但是当我尝试编译测试时出现错误:

Execution failed for task ':app:dexDebugTest'.
trouble writing output: Too many method references: 70561; max is 65536.
You may try using --multi-dex option.

好的,我找到了 multiDexEnabled 属性并添加了

multiDexEnabled true

在里面

defaultConfig

我还扩展了我的应用程序

MultiDexApplication

但这并没有改变任何东西,我仍然得到

Execution failed for task ':logic:dexDebugTest'.
trouble writing output: Too many method references: 70561; max is 65536.
You may try using --multi-dex option.

它甚至明确地向我展示了没有 --multi-dex 参数的 dx 命令

sdk/build-tools/21.1.1/dx --dex --output /build/intermediates/dex/test/debug --input-list=build/intermediates/tmp/dex/test/debug/libraryList.txt
4

1 回答 1

0

尝试将此添加到您的 build.gradle

android{

...

afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }.each { dx ->
            if (dx.additionalParameters == null) {
                dx.additionalParameters = ['--multi-dex']
            } else {
                dx.additionalParameters += '--multi-dex'
            }
        }
    }

...
}
于 2014-11-12T11:04:37.967 回答