AndroidRuntime:关闭VM

时间:2016-01-12 11:47:43

标签: java android google-play-services google-api-java-client google-api-client

我正在建立一个安卓游戏。这是一个导出到Android Studio的Unity3D项目。我试图在Android Studio中管理所有Google Play服务(GPS)互动。这是负责与GPS交互的类(我知道我没有遵循标准的编程模式):

package com.lemondo.eyescube;

import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;

public class GPSBinding implements ConnectionCallbacks, OnConnectionFailedListener {

    public GoogleApiClient googleApiClient;

    private static GPSBinding _gpsBindingInstance;
    public static GPSBinding instance(){
        if(_gpsBindingInstance == null){
            _gpsBindingInstance = new GPSBinding();
        }
        return _gpsBindingInstance;
    }

    public static void Initialize(){
        if(instance().googleApiClient == null) {
            instance().googleApiClient = new GoogleApiClient.Builder(UnityPlayer.currentActivity)
                    .addConnectionCallbacks(instance())
                    .addOnConnectionFailedListener(instance())
                    .addApi(Games.API)
                    .addScope(Games.SCOPE_GAMES)
                    .build();
        }
    }

    public static void AuthenticatePlayer() {
        Log.d("GPSBinding", "AuthenticatePlayer");
        try {
            if (instance().googleApiClient != null)
                instance().googleApiClient.connect();
            else
                Log.d("GPSBinding", "AuthenticatePlayer: googleApiClient is null");
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onConnected(Bundle bundle) {
    }

    @Override
    public void onConnectionSuspended(int i) {
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
    }

}

这就是:应用程序启动,Unity在启动时调用 Initialize()方法,等待1秒钟并调用 AuthenticatePlayer()方法。

应用程序在 Authenticatelayer()

中的此行崩溃
instance().googleApiClient.connect();

我没有得到原因,这是堆栈跟踪:

01-12 12:46:02.602 30609-30609/com.lemondo.eyescube D/AndroidRuntime: Shutting down VM
01-12 12:46:02.605 30609-30609/com.lemondo.eyescube E/AndroidRuntime: FATAL EXCEPTION: main
01-12 12:46:02.605 30609-30609/com.lemondo.eyescube E/AndroidRuntime: Process: com.lemondo.eyescube, PID: 30609
01-12 12:46:02.605 30609-30609/com.lemondo.eyescube E/AndroidRuntime: java.lang.Error: FATAL EXCEPTION [main]
01-12 12:46:02.605 30609-30609/com.lemondo.eyescube E/AndroidRuntime: Unity version     : 5.2.1f1
01-12 12:46:02.605 30609-30609/com.lemondo.eyescube E/AndroidRuntime: Device model      : samsung GT-I9500
01-12 12:46:02.605 30609-30609/com.lemondo.eyescube E/AndroidRuntime: Device fingerprint: ...
01-12 12:46:25.139 30609-30609/com.lemondo.eyescube I/Process: Sending signal. PID: 30609 SIG: 9

关于SO的类似问题只是说调整Google Analytics,我完全不会使用它。奇怪的是它甚至没有例外 - 只是轰!崩溃!有谁知道什么可能是错的?提前谢谢!

1 个答案:

答案 0 :(得分:0)

愚蠢的愚蠢 - 我忘了在我的清单中添加app id:

<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" />