我们已将Google Play Services C ++ SDK(1.1)集成到我们的Android应用中。我们的测试物理设备是Android API 4.0.3。 Google Play服务可以运行,玩家可以访问,解锁成就和排行榜。
但是,我们遇到了一个问题,我们无法在启动过程中自动登录,错误代码为-3。 应用启动后,我们可以手动登录。启动期间捕获了以下logCat记录。
08-07 09:31:34.045 6724 6724 I main : Initializing Services
08-07 09:31:34.045 6724 6724 I main : Uninitialized services, so creating
08-07 09:31:34.139 6724 6724 I dalvikvm: Could not find method android.view.View.getDisplay, referenced from method com.google.android.gms.games.internal.PopupManager$PopupManagerHCMR1.h
08-07 09:31:34.139 6724 6724 W dalvikvm: VFY: unable to resolve virtual method 5238: Landroid/view/View;.getDisplay ()Landroid/view/Display;
08-07 09:31:34.139 6724 6724 I dalvikvm: Could not find method android.view.ViewTreeObserver.removeOnGlobalLayoutListener, referenced from method com.google.android.gms.games.internal.PopupManager$PopupManagerHCMR1.g
08-07 09:31:34.139 6724 6724 W dalvikvm: VFY: unable to resolve virtual method 5417: Landroid/view/ViewTreeObserver;.removeOnGlobalLayoutListener (Landroid/view/ViewTreeObserver$OnGlobalLayoutListener;)V
08-07 09:31:34.139 6724 6724 W PopupManager: You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
08-07 09:31:34.139 6724 6724 I main : Created
08-07 09:31:34.139 6724 6753 I GamesNativeSDK: Connecting to Google Play...
08-07 09:31:34.928 6724 6724 I dalvikvm: Could not find method android.webkit.WebSettings.getDefaultUserAgent, referenced from method afz.a
08-07 09:31:34.928 6724 6724 W dalvikvm: VFY: unable to resolve static method 3655: Landroid/webkit/WebSettings;.getDefaultUserAgent (Landroid/content/Context;)Ljava/lang/String;
08-07 09:31:34.967 6724 6724 I Ads : Starting ad request.
08-07 09:31:35.084 6724 6724 I Ads : Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
08-07 09:31:35.100 6724 6724 I dalvikvm: Could not find method android.webkit.WebSettings.setMediaPlaybackRequiresUserGesture, referenced from method agk.<init>
08-07 09:31:35.100 6724 6724 W dalvikvm: VFY: unable to resolve virtual method 3670: Landroid/webkit/WebSettings;.setMediaPlaybackRequiresUserGesture (Z)V
08-07 09:31:35.475 405 436 I AlarmManager: sending alarm Alarm{41c0fbc0 type 2 com.android.phone}, PendingIntent{420f7740: PendingIntentRecord{41caf830 com.android.phone broadcastIntent}}
08-07 09:31:36.287 6724 6765 E GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-07 09:31:36.647 405 437 I ActivityManager: Displayed com.MyApp.app/org.cocos2dx.cpp.AppActivity: +4s610ms
08-07 09:31:36.670 6724 6753 I GamesNativeSDK: UI interaction required to connect to Google Play.
08-07 09:31:36.670 6724 6754 I main : Sign in finished with a result of -3
我们在OnCreate方法中初始化了Game Services。 以下代码显示了相关的实现。注意到我们的应用程序扩展了标准Java活动。
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
nativeInitGPGS(this); // create Google Player Services
nativeOnActivityCreated(this, savedInstanceState);
}
方法参考C ++方法如下
JNIEXPORT void
Java_org_cocos2dx_cpp_AppActivity_nativeInitGPGS(JNIEnv* env, jobject thiz, jobject activity)
{
gpg::AndroidPlatformConfiguration platform_configuration;
platform_configuration.SetActivity(activity);
GPGSManager::InitServices(platform_configuration);
}
JNIEXPORT void
Java_org_cocos2dx_cpp_AppActivity_nativeOnActivityCreated(
JNIEnv* env, jobject thiz, jobject activity, jobject saved_instance_state) {
gpg::AndroidSupport::OnActivityCreated(env, activity, saved_instance_state);
}
void GPGSManager::InitServices(gpg::PlatformConfiguration &pc)
{
LOGI("Initializing Services");
if (!gameServices) {
LOGI("Uninitialized services, so creating");
gameServices = gpg::GameServices::Builder()
.SetLogging(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE)
.SetOnAuthActionStarted([](gpg::AuthOperation op){
OnAuthActionStarted(op);
})
.SetOnAuthActionFinished([](gpg::AuthOperation op, gpg::AuthStatus status){
LOGI("Sign in finished with a result of %d", status);
if( status == gpg::AuthStatus::VALID )
isSignedIn = true;
else
isSignedIn = false;
OnAuthActionFinished( op, status);
}).Create(pc);
}
LOGI("Created");
}