I’m trying to add GooglePlay Leaderboards and Achievements into my plugin, but keep getting the error:
As far as I know iv’e done everything correctly. Added the “google-play-services_lib” project to my native Java eclipse project, added it as a “Reference”, added the “google-play-services.jar” to that project and to the Unity plugins folder. I have also set “google-play-services.jar” to export its entries and can see in my “R.txt” file the entries are there.
I never figured it out. And after more research found that GooglePlayServices may not even work on some Android 2.3 devices… at least it looked that way. So I reverted back to using the normal AdMob framework. And I decided not to support there leaderboard systems for now as there are better options out there for Android like Scoreoid that will work out of the box on any device.
The GooglePlay services libs seem to be in lala land right now… so I rly don’t know whats up with it.
That’s because the R.java class is regenerated by Unity once you compile your project, so all references to R class on Eclipse are lost.
A quick fix could be copy these values to your Assets/Plugins/Android/res/values folder, then when Unity regenerate the R class will include the values. But, keep in mind the Google Play library is referencing their own R.class, you should make sure to reference the correct R class (your plugin) on the Google Play library or this will not work.
Unfortunately, it is not harmless. If you run on a device with no google play services installed, then you’ll have a problem because it needs to display an error dialog asking the user to download (or upgrade or enable depending on the situation) google play services. That dialog requires resources, and the logcat message is telling you that you don’t have them. So be warned, your app will not work on older devices that do not have it preinstalled or do not have the latest version or do not have it enabled in their settings.
I have not been able to find a good work around for this in Unity.
Start with your Eclipse plugin project. Go to properties → android → add library. Add the google-play-services-lib that you copied and imported from the sdk folder. Click apply.
Make sure your plugin project is marked as a library.
Drag the jar for your plugin only into the Plugins->Android folder in your Unity project. You’ll also need to have your manifest file and a res->values->id.xml file in there with your app id. If you put the google-play-services-lib.jar in that folder, you’ll get multiple dex files when you try to do a final build.
Export your Unity project as an Eclipse project.
Import the Unity project into your Eclipse workspace.
Link the google-play-services-lib to this new project like you did in step 1.
Build your apk in Eclipse
I also put the google play services version number in the manifest instead of referencing a string value from the res folder. That was giving me errors. If you get some error about translations, go to Window → Preferences → Android → Lint and change the translation error from fatal to warning. I think thats abou it. If you get multiple dex errors after all of this, try redoing your plugin with a fresh workspace.
Also, I get the Google Play resources not found in logcat all the time on all of my devices. Everything still works fine.
Thanks, this is working. I’m still having the print in logcat too though, which still seems rather problematic as salqadri pointed out. I don’t get why it happens, if jvil could explain more in detail about the R.java file; isn’t there one per project ? Following the steps to build in eclipse, shouldn’t the google-play-services_lib’s R.java be generated by eclipse, and not unity ? And then why wouldn’t it find the resources then ? I’m rather lost with this R.java generation thing.
Also, I don’t understand the workaround of jvil. I’ve tried moving the res folder from Plugins/Android/google-play-services_lib/res to Plugins/Android/res, but that didn’t solved the error message. How can I “make sure to reference the correct R class (your plugin) on the Google Play library” ?
I’ve tried building with ant. Same result.
I’ve unpacked the apk using apktool, and the google services ones are indeed inside.
Anyone has the solution to this ?
Thanks! I’m not too sure if I’m getting step 1 right, though… Is there a project included with NerdGPG? Or you created one from scratch, and manually imported the sources? Also, what do you mean with “Add the google-play-services-lib that you copied and imported from the sdk folder.”? Did you drag the google-play-services.jar into the plugin project?
Thanks in advance for any help, I’m also getting this error in my Android project
Copy the library project at /extras/google/google_play_services/libproject/google-play-services_lib/ to the Unity Plugins/Android folder. That’s the simplest solution i have found.