0

So I've been trying to solve this problem the whole day yesterday. My app should connect to GooglePlay (in order to acces leaderboards) but as soon as I run the GoogleApiClient.connect() method, the app crashes (the same problem with .enableAutoManage). I can't even catch an error, because the client seems to run a new thread.

I initialize the GoogleApiClient as follows:

 GoogleApiClient gaClient;
 gaClient = new GoogleApiClient.Builder(this)
        .addOnConnectionFailedListener(this)
        .addApi(Games.API).addScope(Games.SCOPE_GAMES)
        .build();

As soon as I run gaClient.connect() the app crashes even if I put a try-catch statement around it. The onConnectionFailed listener does not get activated. I hava the following dependencies on the project

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.google.android.gms:play-services-games:11.0.2'
compile 'com.google.android.gms:play-services-auth:11.0.2'
compile 'com.google.android.gms:play-services-ads:11.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12' }

I also tried the version: 11.0.4

The stacktrace looks like this:

java.lang.NullPointerException: Attempt to invoke virtual method 'int com.huawei.lcagent.client.LogCollectManager.getUserType()' on a null object reference
 at com.android.server.util.ReportTools.getUserType(ReportTools.java:86)
 at com.android.server.util.ReportTools.isBetaUser(ReportTools.java:73)
 at com.android.server.util.ReportTools.report(ReportTools.java:58)
 at com.android.server.util.HwUserBehaviourRecord.appExitRecord(HwUserBehaviourRecord.java:65)
 at com.android.server.am.ActivityManagerService$UiHandler.handleMessage(ActivityManagerService.java:1523)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:150)
 at android.os.HandlerThread.run(HandlerThread.java:61)
 at com.android.server.ServiceThread.run(ServiceThread.java:46)

Because of the stacktrace I believe it has something to do with my phone, but unfortunately I don't have acces to another one or even an emulator. Is there any workaround if this can't be fixed?

I also miss a function to let the user choose which account he wants to choose, is this integrated in the connect() method already?

I am aware that there is a very similar question already, but none of the answers worked for me.

Thanks in advance!

Regedit
  • 31
  • 5

1 Answers1

0

You need to add ConnectionCallback as well when you build your GoogleApiClient.

Add this to its initialization.

GoogleApiClient gaClient;
gaClient = new GoogleApiClient.Builder(this)
    .addOnConnectionFailedListener(this)
    .addConnectionCallbacks(this) // with this you will have to implement another method onConnected and then .connect method will work fine.
    .addApi(Games.API).addScope(Games.SCOPE_GAMES)
    .build();
Aalap Patel
  • 2,058
  • 2
  • 17
  • 31
  • Thanks but this does not work either, none of the methods is called (I think I had these implemented once, forgott to mention that) – Regedit Sep 14 '17 at 16:18
  • I saw the stackTrace and observe that error is on line `LogCollectManager.getUserType()` please post code related to this.. – Aalap Patel Sep 14 '17 at 16:51
  • The problem is, that I never call that method or even use `LogCollectManager`, this line is called by the GoogleApiClient after I run the `connect()` method – Regedit Sep 14 '17 at 19:39