且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有Google Play游戏服务的LIBGDX游戏配置错误

更新时间:2023-01-01 10:39:45

以下几点可能对您有所帮助.

  • 要花几小时才能真正发布您在开发者控制台上所做的更改.几个小时后测试游戏.

  • 您无需发布即可对其进行测试.您可以通过在开发人员控制台中添加测试人员帐户来做到这一点.

  • 您无法使用开发者帐户测试" Google Play服务.您将需要另一个帐户.

非常重要:

确保已在Android项目中为AndroidManifest.xml添加了必需的权限.

I am a starter with Libgdx and Android. I have developed a small game. I have tried following up Google play game services tutorial at https://github.com/TheInvader360/libgdx-gameservices-tutorial using super jumper example. I have also checked every thing on Google developers Documentation.Also I have followed this tutorial http://forum.xda-developers.com/android/apps-games/setting-eclipse-to-google-play-game-t2889796 Plus stack overflow.

a. SHA1 key is same when application Is EXPORT from eclipse.

b. Client ID is generated by O Auth2.0

c. Application package name is same .

d. My game is already published.

e. I also published Google play Game Services.(Its written on Google developer documentation that if app is published then also publish game services)

f. I upload Signed apk generated by Eclipse on my device for testing. but no luck.

The error I got is that "Failed to sign in. Please check your network connection and try again. "

My application Manifest file is

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="...."
    android:versionCode="1"
    android:versionName="1.1" >

    <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="20" />


     <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application
        ......>
     <activity ....../>
        <meta-data
    android:name="com.google.android.gms.analytics.globalConfigResource"
    android:resource="@xml/global_tracker" />
    <meta-data android:name="com.google.android.gms.games.APP_ID"
    android:value="@string/app_id" />

   <meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version"/>
    </application>
</manifest>

the configuration that I gave in my main Android Class is

public class AndroidLauncher extends AndroidApplication implements
    ActionResolver, GameHelperListener ,          GoogleApiClient.ConnectionCallbacks, 
    GoogleApiClient.OnConnectionFailedListener {

    private GameHelper gameHelper;
    private GoogleApiClient client;

    @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
              client = new GoogleApiClient.Builder(this)
                .addApi(Games.API)
                .addScope(Games.SCOPE_GAMES)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();


           GameHelper.GameHelperListener gameHelperListener = new GameHelper.GameHelperListener() {
              @Override
              public void onSignInFailed() {
                  Log.i("Game Helper", "Sign in failed");
              }

              @Override
              public void onSignInSucceeded() {
                  Log.i("Game Helper", "Sign in succeeded");
              }
          };



      gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES); 


      gameHelper.enableDebugLog(true);



           AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
            initialize(new MainGame(this) , config);                                                                
        gameHelper.setup(gameHelperListener );

          }

     @Override
     public void onStart() {
         super.onStart();
            gameHelper.onStart(this);
        client.connect();
      }

      @Override
    public void onStop() {
      super.onStop();

      gameHelper.onStop();
      client.disconnect();
      }


     @Override
        public void onActivityResult(int request, int response, Intent data)      {
       super.onActivityResult(request, response, data);
        gameHelper.onActivityResult(request, response, data);
      }

      @Override
      public boolean getSignedInGPGS() {

         return gameHelper.isSignedIn();
      }

        @Override
      public void loginGPGS() {
       try {
          runOnUiThread(new Runnable() {
              public void run() {
                  gameHelper.beginUserInitiatedSignIn();
              }
            });
       } catch (final Exception ex) {
                   }
     }

      @Override
     public void unlockAchievementGPGS(String achievementId) {

         Games.Achievements.unlock(gameHelper.getApiClient(), achievementId);

     }

      @Override
       public void getLeaderboardGPGS() {

     }

     @Override
      public void getAchievementsGPGS() {
       if (gameHelper.isSignedIn()) {
        startActivityForResult(
                  Games.Achievements.getAchievementsIntent(gameHelper
                        .getApiClient()), 101);
             } else if (!gameHelper.isConnecting()) {
               loginGPGS();
            }

            }

        @Override
       public void onSignInFailed() {
         System.out.println("Sign in succeeded");

       }

      @Override
      public void onSignInSucceeded() {
           System.out.println("Sign in failed");

       }

       @Override
       public void submitScoreGPGS(int score) {
           // TODO Auto-generated method stub

       }

      @Override
        public void onConnectionFailed(ConnectionResult arg0) {
          // TODO Auto-generated method stub

       }

       @Override
        public void onConnected(Bundle arg0) {
              Log.i("Google API", "Connection Complete");

       }

        @Override
        public void onConnectionSuspended(int arg0) {
            Log.i("Google API", "Connection Failed: " );

        }

          }

I have given the exact same app id in my string file in the resource folder. I dont get it why I get this error.

action resolver interface has all the methods specified. Main Game class initiate this interface.

On Game over I send score to unlock achievements. I only have Achievements in my game. Any other piece of Code is needed I can provide but kindly help me out.

Here are a few points that might help you.

  • It takes several hours before your changes on Developer Console are actually published. Test the game after a few hours.

  • You don't need to publish in order to test it. You can do that by adding tester accounts in your developer console.

  • You can't "test" Google Play Services with developer account. You will need another account for that.

Edit: Very Important:

Make sure you added required permissions to AndroidManifest.xml in your Android project.