I’ve upgraded some of the projects I’ve been working on to Unity 5 and at the same time, I upgraded the Google Play Unity plugin to the latest version.
The GP plugin now uses AAR files (a android library file) instead of JARs (a standard java library file). Unity 5 prefers AAR’s so that makes sense. However, I ran into a headscratcher when my plugins (JAR files) started giving me the ‘java.lang.NoSuchMethodError’ errors again.
I verified I had all the libraries I needed in my Plugin folder so I couldn’t see what the problem was. As I was messing with various debug additions I noticed the the standard GooglePlay folder was being deleted by something in Unity from my Plugin folder, and that this was the root of the problem.
A little more digging and I discovered that the new version of the GPlay plugin will remove that folder from Plugin/Android and then includes the ‘referenced’ parts of the library when you compile it for your android build. As their plugin didn’t use the advertising or analytic’s part of the GPlay libraries, it was not including it in the final APK, and my plugins would then fail as I use both of those.
They have a mechanism to create a c# class that their code will pull in and let you add additional dependencies, which in turn enables those sections to be included in the APK. I wasn’t able to figure that out, and in frustration (I’d already spent several hours tracking this down) I just modified a file in their plugin to include the dependencies I wanted.
I modified the static constructor by adding two lines to PlayServicesResolver.cs
svcSupport = PlayServicesSupport.CreateInstance(
//CG –– added the following two lines
svcSupport.DependOn(“com.google.android.gms“, “play–services–ads“, GooglePlayGames.PluginVersion.PlayServicesVersionConstraint);
svcSupport.DependOn(“com.google.android.gms“, “play–services–analytics“, GooglePlayGames.PluginVersion.PlayServicesVersionConstraint);
These two lines keep the analytics and AdMob modules in the final APK and most importantly, let my plugins function as expected. When I have time, I’ll figure out the correct way to do this.