基本上,googleApiClient能够连接。但是,如果我将Games.API添加到APIclient,则会发生一些未捕获的异常。我几乎到处搜索,但似乎没有人有这个问题。一旦我从Builder中删除Games.API,它就会正常连接。 但我需要Games.API在我的游戏中包含排行榜。 请有人帮帮我吗?
logcat的:
07-09 00:43:19.709 14636-14636/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x418c49a8)
07-09 00:43:19.709 14636-14636/? W/dalvikvm﹕ threadid=1: uncaught exception occurred
07-09 00:43:19.709 14636-14636/? W/System.err﹕ java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at com.google.android.gms.common.internal.zzi$zza.zzc(Unknown Source)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at com.google.android.gms.common.internal.zzi$zza.zzr(Unknown Source)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at com.google.android.gms.common.internal.zzi$zzc.zznQ(Unknown Source)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at com.google.android.gms.common.internal.zzi$zzb.handleMessage(Unknown Source)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:107)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at android.os.Looper.loop(Looper.java:194)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5405)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:525)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:838)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
07-09 00:43:19.724 14636-14636/? W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
07-09 00:43:19.724 14636-14636/? W/dalvikvm﹕ threadid=1: calling UncaughtExceptionHandler
07-09 00:43:19.725 14636-14636/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
at com.google.android.gms.common.internal.zzi$zza.zzc(Unknown Source)
at com.google.android.gms.common.internal.zzi$zza.zzr(Unknown Source)
at com.google.android.gms.common.internal.zzi$zzc.zznQ(Unknown Source)
at com.google.android.gms.common.internal.zzi$zzb.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5405)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:838)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
清单:
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="480680880602" />
<meta-data
android:name="com.google.android.gms.appstate.APP_ID"
android:value="480680880602" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
代码:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addApi(Games.API)
.addApi(AppStateManager.API)
.addScope(AppStateManager.SCOPE_APP_STATE)
.addScope(Games.SCOPE_GAMES)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
public void onConnected(Bundle connectionHint) {
Toast.makeText(Homepage.this, "CONNECTED", Toast.LENGTH_SHORT).show();
SharedPreferences load=getSharedPreferences("mysavegame", MODE_PRIVATE);
int a=load.getInt("score", 0);
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
// Games.Leaderboards.submitScore(mGoogleApiClient, "CgkI2tPA1v4NEAIQAA", a);
}
Toast.makeText(Homepage.this, "SCORE SUBMITTED", Toast.LENGTH_SHORT).show();
// Connected to Google Play services!
// The good stuff goes here.
}
游戏链接:https://play.google.com/store/apps/details?id=com.iitb.nihar.declarecardgame
答案 0 :(得分:2)
可能不是您问题的完整解决方案,但问题的一部分肯定是您正在将app_id硬编码到清单中。那不行。刚尝试过,我也遇到了同样的崩溃。
您需要使用“@ string / app_id”来引用res / values / something.xml文件。
**如果您将app_id的值添加到/res/values/strings.xml文件中,这将有效。
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" />
这将不工作。
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="123456789" />
在/res/values/strings.xml
<resources>
<string name="app_id">123456789</string>
</resources>
即使你在/res/values/file.xml中放了一个app_id,如果它不是一个有效的app_id,你也会遇到同样的崩溃。
答案 1 :(得分:0)
我有同样的问题。我使用Eclipse作为IDE,Eclipse将访问AndroidManifest以检查minSdkVersion
或targetSdkVersion
。而且我不确切地知道原因,Games.API
如果targetSdkVersion
是&gt; 19.所以:
ANDROID_HOME/sdk/extras/google/google_play_services/libproject/google-play-services_lib
复制到项目的同一文件夹(实际上是相同的硬盘分区)。<uses-sdk android:targetSdkVersion="19"/>
如果异常继续显示或您正在使用Android Studio。您可以尝试将设备上的google play service sdk和goole play服务升级到最新版本(https://github.com/playgameservices/play-games-plugin-for-unity/issues/489)