I'm trying to add Google Games Services to my native Android game. gpg::GamesServices::Builder::Create
is returning NULL and the following is printed in logcat:
E/GamesNativeSDK(pid): Error emptying previous jar directory.
E/GamesNativeSDK(pid): Could not load additional classes from embedded jar.
My native code is very simple:
gpg::AndroidInitialization::JNI_OnLoad( javaVM );
gpg::AndroidPlatformConfiguration platform_configuration;
platform_configuration.SetActivity( activity );
gpg::GamesServices::Builder builder;
service = builder
.SetOnAuthActionStarted([this](gpg::AuthOperation op) { OnAuthActionStarted(op); })
.SetOnAuthActionFinished([this](gpg::AuthOperation op, gpg::AuthStatus status) { OnAuthActionFinished(op, status); })
.EnableSnapshots()
.Create(platform_configuration);
My project.properties contains:
android.library.reference.3=extras/play_services/library
Which is where I put the Google Play Services library. When I run ant, I see it's including extras/play_services/library/bin/classes.jar
and lib/google-play-services.jar
I'm not using proguard.
Turns out you have to call AndroidInitialization::JNI_OnLoad from within JNI_OnLoad. You can't call it arbitrarily when you want to initialize GPG.
PieNoon has a great example of using JNI_OnLoad: https://github.com/google/pienoon/blob/master/src/gpg_manager.cpp