Android crash on GooglePlayServices (Games) connect

匿名 (未验证) 提交于 2019-12-03 01:11:01

问题:

I'm messing around with this problem about 10h and i cann't figure out what i've done wrong....

The Fatal Exception:

E/AndroidRuntime: FATAL EXCEPTION: main    Process: onl.deepspace.zoorallye, PID: 13256    java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.    at com.google.android.gms.common.internal.zzj$zza.zzc(Unknown Source)    at com.google.android.gms.common.internal.zzj$zza.zzw(Unknown Source)    at com.google.android.gms.common.internal.zzj$zzc.zzqN(Unknown Source)    at com.google.android.gms.common.internal.zzj$zzb.handleMessage(Unknown Source)    at android.os.Handler.dispatchMessage(Handler.java:102)    at android.os.Looper.loop(Looper.java:135)    at android.app.ActivityThread.main(ActivityThread.java:5569)    at java.lang.reflect.Method.invoke(Native Method)    at java.lang.reflect.Method.invoke(Method.java:372)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:931)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:726) 

The Log does not provide any important information


I was looking around google, i could fix some errors. But the App always crashes here:

achievements.googleApiClient.connect();

MainActivity (important parts):

Achievements achievements;  @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);      ...      //Init Achievements     achievements = new Achievements(this);     achievements.googleApiClient.connect(); //**AppCrash** }  @Override protected void onStart() {     super.onStart(); }  @Override protected void onStop() {     super.onStop();     achievements.googleApiClient.disconnect(); }     

Achievements.java:

public class Achievements implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks{  public GoogleApiClient googleApiClient; private Activity activity;  public Achievements(Activity activity){     this.activity = activity;      googleApiClient = new GoogleApiClient.Builder(activity)             .addConnectionCallbacks(this)             .addOnConnectionFailedListener(this)             .addApi(Games.API)             .addScope(Games.SCOPE_GAMES)             .build(); }  private void signIn(GoogleApiClient signinClient) {     Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(signinClient);     activity.startActivityForResult(signInIntent, 0); }  @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {     if(connectionResult.getErrorCode() == ConnectionResult.SIGN_IN_REQUIRED){         signIn(Tools.getSigninClient(activity));     }     Toast.makeText(activity, connectionResult.getErrorMessage(), Toast.LENGTH_SHORT).show();     Log.e(Const.LOGTAG, connectionResult.getErrorMessage()); }  @Override public void onConnected(@Nullable Bundle bundle) {     Log.i(Const.LOGTAG, "Play Service (Games) Connected"); }  @Override public void onConnectionSuspended(int i) { } } 

AndroidManifest.xml:

     <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="onl.deepspace.zoorallye">  <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  <application     android:allowBackup="true"     android:icon="@mipmap/appicon"     android:label="@string/app_name"     android:supportsRtl="true"     android:theme="@style/AppTheme">      <activity         android:name=".MainActivity"         android:label="@string/app_name"         android:theme="@style/AppTheme.Drawer"></activity>      <meta-data         android:name="com.google.android.gms.version"         android:value="@integer/google_play_services_version" />     <meta-data         android:name="com.google.android.gms.games.onl.deepspace.zoorallye"         android:value="@string/google_app_id" />  </application> 

回答1:

Looked around the community for similar posts and found this answer, check it out. Gonna go straight to the point, I think the cause of this issue is in your AndroidManifest.xml. As mentioned in the answer, the <meta-data> tag should be added, yours is there, but the name is different. It shows as:

android:name="com.google.android.gms.games.onl.deepspace.zoorallye"

while in the answer above, it shows:

android:name="com.google.android.gms.games.APP_ID"

Went to the Google Quickstart samples and notice that all of the tags are like the above. Haven't seen anything else in your code that's causing the issue. Hope this helps. Good luck.



回答2:

I believe this might be related to missing the com.google.android.gms.games.APP_ID metadata element in your AndroidManifest.xml

It looks like a typo (you replaced APP_ID with your package name?). It should be: <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" />

You can refer to TypeANumber basic sample's AndroidManifest.xml https://github.com/playgameservices/android-basic-samples/blob/master/BasicSamples/TypeANumber/src/main/AndroidManifest.xml#L41



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!