I’ve been working on updating my Unity3D Android plugins, and decided to make a new project to test them in. On and off for the past few days I’ve been trying to nail down the reason for the following error:
AndroidJavaException: java.lang.NoSuchMethodError: no static method “Lcom/purplebuttons/unity/PBAndroidUtils;.PBInitAndroidUtils(Lcom.unity3d.player.UnityPlayerNativeActivity;Z)V”
I get this error when the plugin is initialized, and it looks like Unity can’t find my static method. I checked my parameters, verified that the method name was correct, checked that the JAR was in my plugins/android folder. Everything checked out, but I was still getting the error.
I rolled the plugin back to a version from another project I knew worked as intended. No difference, same error. Lots of google searching and still nothing obvious. The most common cause is either the parameters not matching, an incorrect java class path, or a misspelled method name. I had none of those.
So I duplicated a working project that called the plugin without any errors, and started stripping it back. Removed lots of scripts, objects, images & sounds. Finally I started pairing down the plugins/android directory, and that’s when it happened – I found the error.
Turns out I needed to include the ‘google-play-services_lib’ in my plugins/android folder. The plugin jar used various bits & bobs from this lib and without it included in the APK, the plugin would fail to load when called, and return the error above, which didn’t really explain what was going on.
When I created the test project, I didn’t think to copy that forward, and hence my wasted time…