Hi,
I am working on a project which has an Android version. As we’ve updated SDKs we’re now hitting the 65536 method DEX limit in Android. (Enable multidex for apps with over 64K methods | Android Studio | Android Developers). We therefore want to build the game using Gradle as this should allow us to use either multidex or ProGuard to fix this problem.
I’m new to this particular project, Android build systems, Android Studio, and Gradle however I’ve used Unity for long enough to be reasonably competent. However my limited knowledge of the Android-specific build systems is cause me some problems. I’ve searched extensively but haven’t found any solutions. I’ll explain what I’ve done and the problem I am now facing.
- Using Unity 5.6.0f3
- Using Android Studio 2.3.2
- java -version reports java version “1.8.0_131”
- I exported the Android project from Unity 5.6 Build Settings window as Gradle (New).
- Then imported this Gradle project into Android Studio 2.3.2
- AS showed a variety of error messages, mostly relating to AndroidManifest.xml collisions, so I edited these xml files (they’re in the project folder), until those errors were resolved.
- I also had edited several build.gradle files in the exported Gradle project where it says: classpath ‘com.android.tools.build:gradle:2.1.0’, and changed 2.1.0 to 2.3.2, because of the recommendation on this page : Informacje o wersji 8.5 wtyczki Androida do obsługi Gradle | Android Studio | Android Developers
- Making those changes eventually resulted in Android Studio reporting “BUILD SUCCESSFUL”
- I then switched back to Unity
- Go to File->Build Settings… window and hit the ‘Build’ button. (Build System is still set to ‘Gradle (New)’ as it was when I exported the project from this window).
- I am then presented with an error message as follows:
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_121\bin\java.exe -classpath “C:\Program Files\Unity5.6.0\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-2.14.jar” org.gradle.launcher.GradleMain “assembleRelease”
stderr[
FAILURE: Build failed with an exception.
-
Where:
Build file ‘C:\Sourcetree\game_Android\Unity_Game\Temp\gradleOut\build.gradle’ line: 19 -
What went wrong:
A problem occurred evaluating root project ‘gradleOut’.
Failed to apply plugin [id ‘com.android.application’]
Minimum supported Gradle version is 3.3. Current version is 2.14. If using the gradle wrapper, try editing the distributionUrl in C:\Sourcetree\game_Android\Unity_Game\Temp\gradleOut\gradle\wrapper\gradle-wrapper.properties to gradle-3.3-all.zip
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
]
So it looks like Unity is trying to use the version of Gradle that ships with Unity, which is in : C:\Program Files\Unity5.6.0\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib
In this \lib folder, there are a bunch of .jar files, version number 2.14, so I’m assuming that when Unity is building, it’s using that embedded version of Gradle rather than any other versions on my PC.
I then changed the distributionUrl in the gradle-wrapper.properties file as suggested in the error message, so now in the exported Gradle project folder, my gradle-wrapper.properties now has a line reading:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
That makes no difference and building again gives the same error.
Can anyone suggest how I can solve this?
Thanks.