【问题标题】:Can't Initialize Google Play Services无法初始化 Google Play 服务
【发布时间】:2014-09-08 12:10:25
【问题描述】:

这是我第一次尝试使用 Google Play 服务。

我添加了库“google-play-services-lib”和“BaseGameUtils”。我将我的课程改为扩展“BaseGameActivity”

代码如下:

public class MainActivity extends BaseGameActivity implements View.OnClickListener  {
    Button  skipBut;
    View signInBut;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);

        skipBut = (Button) findViewById(R.id.justPlay);
        signInBut = (View) findViewById(R.id.sign_in_button);
        skipBut.setOnClickListener(this); 
        signInBut.setOnClickListener(this);            

    }

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        if(view.getId() == R.id.sign_in_button){
            beginUserInitiatedSignIn();
        }
        else if(view.getId() == R.id.justPlay){
            // play without sign in .... code ....
        }
    }

@Override
public void onSignInFailed() { 
    // TODO Auto-generated method stub
    Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show();
}

@Override
public void onSignInSucceeded() {
    // TODO Auto-generated method stub
    Toast.makeText(getApplicationContext(), "success", Toast.LENGTH_SHORT).show();
}

}

但是我的应用程序崩溃了。我找不到原因。 注意:我还将应用 ID 添加到 Manifest 和字符串(作为 app_id)。

<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.*****id****"
           android:value="@string/app_id" />

这里是 logCat:

09-08 14:57:19.500: W/ActivityThread(18213): Application com.cdev.colormatch is waiting for the debugger on port 8100...
09-08 14:57:19.520: I/System.out(18213): Sending WAIT chunk
09-08 14:57:19.540: I/dalvikvm(18213): Debugger is active
09-08 14:57:19.720: I/System.out(18213): Debugger has connected
09-08 14:57:19.725: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:19.925: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.125: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.325: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.525: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.725: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.925: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:21.125: I/System.out(18213): debugger has settled (1465)
09-08 14:57:21.505: W/PopupManager(18213): 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.
09-08 14:57:22.225: D/dalvikvm(18213): threadid=1: still suspended after undo (sc=1 dc=1)

更新

我尝试过使用游戏助手而不扩展到 GameBaseActivity(如https://developers.google.com/games/services/android/init#using_gamehelper_without_basegameactivity 中所述)

public class MainActivity extends ActionBarActivity implements View.OnClickListener  {
    Button  skipBut;
    View signInBut;

    GameHelper mHelper;

    boolean mExplicitSignOut = false;
    boolean mInSignInFlow = false;
    GoogleApiClient mClient;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.activity_main);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);



        skipBut = (Button) findViewById(R.id.justPlay);
        signInBut = (View) findViewById(R.id.sign_in_button);
        skipBut.setOnClickListener(this); 
          signInBut.setOnClickListener(this);

        GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this);
            builder.addApi(Games.API)
                   .addApi(Plus.API)
                   .addApi(AppStateManager.API)
                   .addScope(Games.SCOPE_GAMES)
                   .addScope(Plus.SCOPE_PLUS_LOGIN)
                   .addScope(AppStateManager.SCOPE_APP_STATE);
            mClient = builder.build();

            mHelper = new GameHelper(this, GameHelper.CLIENT_ALL);


            GameHelperListener listener = new GameHelper.GameHelperListener() {
                @Override
                public void onSignInSucceeded() {
                    // handle sign-in succeess
                }
                @Override
                public void onSignInFailed() {
                    // handle sign-in failure (e.g. show Sign In button)
                }

            };
            mHelper.setup(listener);


    }

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        if(view.getId() == R.id.sign_in_button){
            mHelper.beginUserInitiatedSignIn();
        }
        else if(view.getId() == R.id.justPlay){
            // skipp sign in
        }
    }
}

但还是崩溃了:(

【问题讨论】:

  • 这是我用作库的 GameHelper 类。你想指出我什么? @2Dee
  • 您指定的 logcat 不包含任何错误,因此很难确定可能是什么问题。使用包含错误(即应用程序崩溃的位置)的副本更新 logcat - 它将以 E 为前缀。
  • 另请注意,当您扩展BaseGameActivity 时,将在onStart 中自动调用登录,因此您的按钮将无法按预期工作。如果你想使用这些按钮,你可以在onCreate 中设置mConnectOnStart=false,或者你应该不扩展GameBaseActivity。仍然没有回答您的问题,但只是提醒一下。

标签: android eclipse google-play-services


【解决方案1】:

关注link

您需要在 onCreate() 中添加一些 java 代码,并尝试按照右栏中的步骤一一进行

 // Java code required.
 // testDevices and loadAdOnCreate attributes are
 // no longer available.
 AdView adView = (AdView)this.findViewById(R.id.adView);
 AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
 adView.loadAd(adRequest);

【讨论】:

  • 我错了还是这个链接是为了说明应用横幅和/或广告? @user1283633
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-06
相关资源
最近更新 更多