Search code examples
androidgradledexandroid-multidex

multiDexEnabled do not work


I have a rather large android project. The project still compiles, but when I try to compile tests I get an error:

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

Ok, I found the multiDexEnabled property and added

multiDexEnabled true

in the

defaultConfig

Also I made my application extend

MultiDexApplication

But it did not change anything, I still get

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

And it even explicitly shows me the dx comand without --multi-dex parameter

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

Solution

  • try adding this to your 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'
                }
            }
        }
    
    ...
    }