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!
You need to add
ConnectionCallback
as well when you build yourGoogleApiClient
.Add this to its initialization.