Well, the history is so far: we hit 64K DEX methods limits again. We did it already two times and managed to bypass it by giving up on some Android plugins or optimizing etc but don’t intend to do it anymore because it’s clearly a dead end, so we’re trying to move to “Multi Dex” building scenario. But when I’m trying to build project using new Gradle build system, it fails with a very known problem:
As we know, Google Play Services add the following meta-data to AndroidManifest.xml (in a Assets\Plugins\Android\MainLibProj\AndroidManifest.xml):
Resource integer “google_play_services_version” previously was located in “/extras/google/google_play_services/libproject/google-play-services_lib/” in a “res/values/version.xml” file. But recent modular Google Play Services libraries store this value within a “play-services-basement-x.y.z.aar” library (in a "res/values/values.xml file) .
So, it looks like Gradle and/or AAPT is not processing correctly resources from AAR libraries, or AAR files are not given to it. And I don’t know who to blame: Unity, Unit-Gradle bridge, Gradle, Android SDK build tools (AAPT) etc? This also gives me a same result if I’m trying to export Gradle project and open it in Android Studio.
This happens both in our big and dirty production project and fresh new empty test project with only
GooglePlayGamesPlugin-0.9.36.unitypackage imported from official Google Play Services from Unity repo.
About my environment:
Unity 5.5.1f1 Win64 on Windows 10.
Latest just updated Android SDK with latest build tools, platform tools, Android SDK, Support library, Google Play Services etc. Path from logs says that Build-tools version 25.0.2 used (latest available).
JDK 1.8.0_102 .
Mono 2.0 scripting backend used.
Android libraries in a Assets\Plugins\Android\ :
play-services-auth-10.0.1.aar
play-services-auth-base-10.0.1.aar
play-services-base-10.0.1.aar
play-services-basement-10.0.1.aar
play-services-drive-10.0.1.aar
play-services-games-10.0.1.aar
play-services-nearby-10.0.1.aar
play-services-tasks-10.0.1.aar
support-annotations-24.0.0.jar
support-v4-24.0.0.aar
All of them were selected automatically by Google Play Services Resolver script as latest available from Android SDK (except for support-* - it selected 24.0.0 even if there’s more recent 24.x.x or even 25.x.x releases).
You should also make sure that these libraries (specifically, play-services-basement-10.0.1.aar) are checked in the plugin inspector to get built into your .apk, otherwise they’re meaningless.
Ok, it seems that I managed to overcome this issue. If I remove
from “Assets/Plugins/Android/MainLibProj/AndroidManifest.xml” and leave it only in a central “Assets/Plugins/Android/AndroidManifest.xml” - then Gradle build compiles successfully. MainLibProj is a folder that comes with “Goole Play Services” package.
It looks that this happens because Google Play Services AAR libraries are referenced from main application “build.gradle” file only, while MainLibProj is a sub-project and it’s missing such references. I still think that this must be fixed somehow between Unity and Google teams, maybe by placing a dependencies on required AAR files to subprojects too. This will require some per-plugin “gradle.build” templating mechanism on Unity side and fixes on Google Play Services Resolver script side, probably, to work smoothly. I see a change in a Unity 5.5.1p1 about “Android: Gradle export now supports custom template”. Can someone from Unity team elaborate and show some examples about it?
OK, I found that if I copy Gradle template from “\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates\mainTemplate.gradle” to “Assets\Plugins\Android\mainTemplate.gradle”, then it gets used in Gradle builds instead of default one. The last step (I hope) is to manage to override my custom application Java class from the current specified in Manifest (it’s Fabric’s app now)…
Not yet. There’s actually a number of various issues (or points where it can be improved) regarding new Android build process using Gradle. I had hopes that this will be discussed first with someone from Unity Android team before formal bugs are filed. Those are including:
This bug with meta-data with GMS version not being processed for dependent libraries by Gradle. This can be either Unity or Gradle issue, I don’t know exactly who is guilty yet, Gradle is too new and complex and this topic needs further research before blaming one side or another.
Built-in Gradle itself and Gradle-Android plugin in Unity are outdated already and needs updating to the latest version continuously. Currently we’re building our project by exporting Android Studio Project and then doing final build from Android Studio because it allows us to use latest Gradle for Android plugin version.
When doing Multidex build, Gradle build can fail because some JAR libraries contains BuildConfig.class classes in their namespaces and Gradle creates its own BuildConfig.class (don’t know why), then it fails on one stage where JAR/AAR are repackaged because of conflicting files. I think this is also more a Gradle-Android plugin bug than Unity. I found only one quick workaround: manually remove BuildConfig.class from those JARs where they’re conflicting. The better solution probably is writing some custom Gradle tasks or pre-post task hooks in Gradle template to remove these duplicates but I failed to find exact one.
Unity really needs improvements in per-project templating mechanism in Gradle builds. Template for buid.gradle (by placing it in Assets\Plugins\Android\mainTemplate.gradle) is really helpful but we also need a template for gradle.properties, for example (too increase memory limits so it performs all tasks in-process - that is more faster and gives less build issues). We overcome this limitation by writing our own post-build hook script.
Thanks. But is it private or not processed yet and not visible because of this? I cannot find it by number.
gms version in library project - i am not sure you can reference a resource (google_play_services_version) that is defined in another library. All android libraries are merged into the final “app”, but one library does not reference another ilbrary, hence the error.
Not sure what gradle version is shipped with Unity, but they should probably aim to keep it up to date… Also - how is exporting an Android studio project working out for you? I find that even for the simplest projects, the process of getting it to build in Android studio is just impossible. Can you briefly describe how you’re doing that?
Haven’t faced this issue as i didn’t use multidex yet.
You can already define a per-project gradle template (just create Plugins/Android/mainTemplate.gradle in your project). For libraries, you still cannot include a per-library template, and i’m also not sure about proguard template per project (need to check).
In any case- i have also reported a few gradle related bugs back in the day, since i really want the support for it to become stable, as we’re also facing the 64k method limit…
Yeah, that is an admirable idea but given the fact that Unity never responded to this post I thought I would go ahead and create a bug and point them to this thread to try and get their attention.
It is currently private. In the latest versions of the Unity Bug Reporter, Unity has removed the option to choose whether a bug report should be made private or public on submit so I don’t know how to turn it into a public bug.
Thanks @AntonBreusov_TatemGames you’ve explained the issues very well, we’re facing the same problems.
I had upgraded to Google Play Game Services v0.9.38a, and in Unity 5.6.1 I was getting the error AAPT: No resource found that matches the given name (at ‘value’ with value ’ @Integer /google_play_services_version’).
The solution you suggested (remove
from “Assets/Plugins/Android/MainLibProj/AndroidManifest.xml” and put that line into “Assets/Plugins/Android/AndroidManifest.xml” - fixed the problem for me.
Thank you for your insight into this problem, I’ve been trying to find the solution all day long!
the issue still exist in untiy 2017.1
I encountered this issue in unity 5.6 then I tried to upgrade my unity editor to 2017 but the issue sitll there.
I tried to create a new empty project and import google play game services plugin, this test project could be build with “internal” but gradle build will throw this “google play services version” issue. so I guess it’s unity’s bug.
and, thanks @AntonBreusov_TatemGames , your solution works for me!
@AntonBreusov_TatemGames - you are a legend. Great work on figuring out how to get round this. You solution worked for me too after a full day’s searching. I’d buy you a beer if you were here.
I’m a little late to reach here but I’m facing the exact same issue and am not able to resolve it like you did. I have the latest Java JDK and Android SDK with all required packages from the Extra section. I have latest GooglePlayGame + GoogleMobileAds + PlayServicesResolver Unity Packages.
I’m not able to build my game because of this error:
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_144\bin\java.exe -classpath "E:\Program Files\Unity\2017.1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-2.14.jar" org.gradle.launcher.GradleMain "assembleRelease"
stderr[
D:\my_work\my_company\my_game\Temp\gradleOut\ChartboostSDK\build\intermediates\bundles\release\aapt\AndroidManifest.xml:26:28-65: AAPT: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':ChartboostSDK:processReleaseResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\Android\android-sdk\build-tools\26.0.0\aapt.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
]
stdout[
Observed package id 'add-ons;addon-unknown-unknown-23' in inconsistent location 'E:\Android\android-sdk\add-ons\addon-google_apis-google-23' (Expected 'E:\Android\android-sdk\add-ons\addon-unknown-unknown-23')
Observed package id 'system-images;android-23;default;armeabi-v7a' in inconsistent location 'E:\Android\android-sdk\system-images\android-23\armeabi-v7a' (Expected 'E:\Android\android-sdk\system-images\android-23\default\armeabi-v7a')
Incremental java compilation is an incubating feature.
:preBuild UP-TO-DATE
:preReleaseBuild UP-TO-DATE
:checkReleaseManifest
:preDebugBuild UP-TO-DATE
:ChartboostSDK:preBuild UP-TO-DATE
:ChartboostSDK:preReleaseBuild UP-TO-DATE
:ChartboostSDK:compileReleaseNdk UP-TO-DATE
:ChartboostSDK:compileLint
:ChartboostSDK:copyReleaseLint UP-TO-DATE
:ChartboostSDK:mergeReleaseProguardFiles UP-TO-DATE
:ChartboostSDK:packageReleaseRenderscript UP-TO-DATE
:ChartboostSDK:checkReleaseManifest
:ChartboostSDK:prepareReleaseDependencies
:ChartboostSDK:compileReleaseRenderscript
:ChartboostSDK:generateReleaseResValues UP-TO-DATE
:ChartboostSDK:generateReleaseResources
:ChartboostSDK:packageReleaseResources
:ChartboostSDK:compileReleaseAidl
:ChartboostSDK:generateReleaseBuildConfig
:ChartboostSDK:mergeReleaseShaders
:ChartboostSDK:compileReleaseShaders
:ChartboostSDK:generateReleaseAssets
:ChartboostSDK:mergeReleaseAssets
:ChartboostSDK:processReleaseManifest
:ChartboostSDK:processReleaseResources FAILED
BUILD FAILED
Total time: 9.561 secs
]
exit code: 1
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <32afc8f7b1124602990c059ee3fb5691>:0)
UnityEditor.Android.GradleWrapper.RunJava (System.String args, System.String workingdir, UnityEditor.Android.GradleWrapper+Progress progress) (at <32afc8f7b1124602990c059ee3fb5691>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.RunJava (System.String args, System.String workingdir, UnityEditor.Android.GradleWrapper+Progress progress) (at <32afc8f7b1124602990c059ee3fb5691>:0)
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, UnityEditor.Android.GradleWrapper+Progress progress) (at <32afc8f7b1124602990c059ee3fb5691>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <32afc8f7b1124602990c059ee3fb5691>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <32afc8f7b1124602990c059ee3fb5691>:0)
UnityEditor.HostView:OnGUI()
UnityEditor.BuildPlayerWindow+BuildMethodException: Build failed with errors.
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x001b9] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:162
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00050] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:83
UnityEditor.HostView:OnGUI()
The error is same but it seems that it is being reported elsewhere (ChartboostSDK)
The latest reply to my bug report from Unity was basically “please try upgrading to the latest version of Unity and let us know if it is still a problem”.
I managed to hack around the problem so haven’t followed up again but I should do so.
I’ve read the thread, and I think the manifest referencing resources from another libraries is just broken (on the google play side). I’m sure it won’t build if you try it in Android Studio, as a non-Unity build.
We are adding references to AARs/libraries automatically during build.
The gradle plugin was also updated in recent Unity versions - it’s not the latest and greatest though - hard to keep up with the pace of new versions released.