Getting Multi Dex working with Gradle

Hello,

I have Unity version 5.5.0f3 and I was trying to use the new Gradle support to get multi dex working so I can use more than 65K functions.

OK, I know that the custom build options are not supported yet, but I took the mainTemplate.gradle file and added in
multiDexExambled true
to the defaultConfig section.

When I try to make a build, gradle fails with the following error

CommandInvokationFailure: Gradle build failed.
C:\Program Files\Java\jdk1.8.0_91\bin\java.exe -classpath “C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-2.14.jar” org.gradle.launcher.GradleMain “assembleRelease”
stderr[
FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘gradleOut’.

Could not resolve all dependencies for configuration ‘:_debugCompile’.
Could not find com.android.support:multidex:1.0.1.
Searched in the following locations:
file:/D:/svn/game/branches/John/helpshift/Temp/StagingArea/gradleOut/libs/multidex-1.0.1.jar
file:/D:/svn/game/branches/John/helpshift/Temp/StagingArea/gradleOut/libs/multidex.jar
Required by:
:gradleOut:unspecified

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    ]
    stdout[
    Incremental java compilation is an incubating feature.
    BUILD FAILED
    Total time: 4.734 secs
    ]
    exit code: 1
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.GradleWrapper.RunJava (System.String args, System.String workingdir, UnityEditor.Android.Progress progress)
    UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, UnityEditor.Android.Progress progress)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

I have done some Googling around for other people who have this issue (but not in Unity). What they said is that you need to install the “Android Support Repository (Obsolete)” from the SDK manager. I actually did have this installed. I found out that in C:\Users\john\AppData\Local\Android\sdk\extras\android\m2repository\com\android\support\multidex\1.0.1 there is a file called multidex-1.0.1.aar. It turns out that a .aar file is a .jar with some extra stuff in there. I was able to extract the .jar file from inside it, rename it to multidex-1.0.1.jar and place it into Assets\Plugins\Android.
If I do this, it will get copied into the correct location in the Temp directory which is required for a Gradle build, but I will then get additional errors where it complains about multidex-instrumentation-1.0.1.jar.

So, is this a valid approach for me to follow to try to get multidex support working, or am I missing something?

Thank You
John Lawrie

Been looking into your error , you can add multidex in dependencies “compile ‘com.android.support:multidex:1.0.1’” found in cradle
also go to your main androidManifest and enable multidex there also in the application tag : android:name=“android.support.multidex.MultiDexApplication”