Java Makes It Safe To Assume The Worst

Today I started getting strange errors whenever I added a dependency to our Android app. The dependencies installed without issue and the project would even build. However attempting to run the project failed with a :dexDebug error.

``` com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 Error:Execution failed for task ':dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2 ```
Abridged error

The problem is that Dalvik (and maybe Java?) has a limited number (65,536!) of addresses for references. The number of available addresses is so large that this normally isn't a problem. In our case we hit that limit just by adding one extra dependency! (Note that this isn't meant to be a poor reflection on the dependency, which is why I'm not calling it out by name. We where already really close, and it just pushed us over the edge.)

The fix is pretty simple, at least for the short term: just enable multiDex in build.gradle. I have no idea what our new reference limit is now, and I definitely don't want to run into it. In the long term, I would love to restructure and simplify/reduce the codebase, but that's not really an option for me at this point.

```language-groovy android { defaultDependencies { multiDexEnabled true } }

dependencies {
compile 'com.android.support:multidex:1.0.0'
}

<figcaption>Enable <code>multiDex</code> in <code>build.gradle</code></figcaption>
</figure>

I'm pretty new to native Android development, so take what I say with a grain of salt. You should also check out [more information on the documentation site](https://developer.android.com/tools/building/multidex.html).