question

Adam Galla avatar image
Adam Galla asked

Google Plus Access Token crash

Hi, I'm working on a game in unity where I want to use the playfab login with google play access id function. For getting the access id I try to use the solutions from the Unity3d_Login_Example. (https://github.com/PlayFab/Unity3d_Login_Example_Project/tree/master/Assets)

After selecting the account, and the plugin starts to get the token, the program crashes, and the log shows this error:

10-29 12:53:03.556 19877-19877/? E/dalvikvm: VM aborting
10-29 12:53:03.556 19877-19877/? A/libc: Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 19877 (ootgames.maz015)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: Activity com.google.android.gms.common.account.SimpleAccountPickerActivity has leaked IntentReceiver com.immersion.android.haptics.HapticFeedbackManager$HapticFeedbackBroadcastReceiver@41bbd750 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-29 12:53:03.572 20016-20016/? E/ActivityThread: android.app.IntentReceiverLeaked: Activity com.google.android.gms.common.account.SimpleAccountPickerActivity has leaked IntentReceiver com.immersion.android.haptics.HapticFeedbackManager$HapticFeedbackBroadcastReceiver@41bbd750 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:800)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:601)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1650)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at android.app.ContextImpl.registerReceiver(ContextImpl.java:1630)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at android.app.ContextImpl.registerReceiver(ContextImpl.java:1624)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:430)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at com.immersion.android.haptics.HapticFeedbackManager.setupPackageBroadcastReceiver(HapticFeedbackManager.java:564)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at com.immersion.android.haptics.HapticFeedbackManager.<init>(HapticFeedbackManager.java:108)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at com.immersion.android.HapticFeedbackManagerProxy.initialize(HapticFeedbackManagerProxy.java:90)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at com.immersion.android.HapticFeedbackManagerProxy.access$100(HapticFeedbackManagerProxy.java:30)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at com.immersion.android.HapticFeedbackManagerProxy$1$1.run(HapticFeedbackManagerProxy.java:71)
10-29 12:53:03.572 20016-20016/? E/ActivityThread: at java.lang.Thread.run(Thread.java:856)

Could you help me please?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image
Hamza Lazaar answered

Yes this is a known issue with the plugin.

You have three options here:
1. Use a workaround: sign in first (SIGN_IN_REASON = 1) and get token in sign in success callback (public void OnSignInSuccess(string googleId) {}). Please ask if you need the code.
2. Wait until this is fixed for good. Your help would be appreciated.
3. Use Google Play Games for Unity plugin which has a way of getting the token now (it wasn't the case when I first created that plugin). I don't recommend this unless you want to use the plugin for other purposes.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

Just making sure all the other threads on this topic have the updated info: We do now support the newer Google authentication (ServerAuthCode) process. Please see this post for more information: https://playfab.com/blog/setting-up-google-sign-in/.

0 Likes 0 ·
Hamza Lazaar avatar image
Hamza Lazaar answered

Hi galla.adam,

Could you please explain how are you trying to get the token? Which method you used and when.

There could be an issue in the first call to getToken after accepting the consent screen but it won't appear again for the same account. Is that it?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Adam Galla avatar image
Adam Galla answered

This is my C# code in unity. It's a monobehaviour, attached to the game object named "_MainMenuLogic". The method below called right in the Start() method.

public void GooglePlusLogin()
{
#if UNITY_ANDROID
int GET_TOKEN_REASON = 2;
string className = "com.ThugLeaf.GooglePlusForUnity.GooglePlusActivity";

AndroidJNI.AttachCurrentThread();
using( AndroidJavaClass activityClass = new AndroidJavaClass(className))
{
    Debug.Log("Using the class"); // The console shows this log, but after this the app crashes
    activityClass.SetStatic<string>("UnityObjectName", "_MainMenuLogic");   
    activityClass.SetStatic<string>("OnTokenReceivedCallback", "OnGoogleTokenReceived"); 
    activityClass.CallStatic("Start", new object[] { GET_TOKEN_REASON });
}
#endif

}

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Adam Galla avatar image
Adam Galla answered

Thanks for your answer. I tried the #1 option.
But now I getting Fatal Exception right after the log "GooglePlusSignIn".

11-03 11:10:33.311 24205-24205/? I/GooglePlusActivity: onCreate 1
11-03 11:10:33.311 24205-24205/? I/GooglePlusActivity: onStart 1
11-03 11:10:33.311 24205-24205/? I/GooglePlusActivity: GooglePlusSignIn
11-03 11:10:33.319 24205-24205/? D/AndroidRuntime: Shutting down VM
11-03 11:10:33.319 24205-24205/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4155f930)
11-03 11:10:33.319 24205-24205/? E/AndroidRuntime: FATAL EXCEPTION: main
11-03 11:10:33.319 24205-24205/? E/AndroidRuntime: java.lang.Error: FATAL EXCEPTION [main]
11-03 11:10:33.319 24205-24205/? E/AndroidRuntime: Unity version : 5.2.1f1
11-03 11:10:33.319 24205-24205/? E/AndroidRuntime: Device model : samsung GT-P5100
11-03 11:10:33.319 24205-24205/? E/AndroidRuntime: Device fingerprint: samsung/espresso10rfxx/espresso10rf:4.2.2/JDQ39/P5100XXDNA1:user/release-keys
11-03 11:10:33.655 498-561/? E/android.os.Debug: !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error

My code looks like I pasted previously, except:
in the using block:
activityClass.SetStatic<string>("UnityObjectName", "MainMenuLogic");
activityClass.SetStatic<string>("OnTokenReceivedCallback", "OnSignInSuccess");

activityClass.CallStatic("Start", new object[] { SIGN
IN_REASON });

the callback method:
public void OnSignInSuccess(string googleId)
{
accessToken = googleId;
PlayFabClientAPI.LoginWithGoogleAccount (new LoginWithGoogleAccountRequest () {
AccessToken = _accessToken,
CreateAccount = true,
TitleId = NetworkInfo.PLAYFAB
TITLE_ID,
}, LoginCallback, ErrorCallback);
}

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image
Hamza Lazaar answered

What I meant by option #1 is the following:
```
AndroidJavaClass activityClass;
const int GET_TOKEN_REASON = 2;
const int SIGN_IN_REASON = 1;
void Start(){
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidJNI.AttachCurrentThread();
activityClass.SetStatic<string>("UnityObjectName", "MainMenuLogic");
string className = "com.ThugLeaf.GooglePlusForUnity.GooglePlusActivity";
activityClass = new AndroidJavaClass(className);
#endif
}

public void GetToken()
{
#if UNITY_ANDROID && !UNITY_EDITOR
activityClass.SetStatic<string>("OnTokenReceivedCallback", "OnGoogleTokenReceived");
activityClass.CallStatic("Start", new object[] { GET_TOKEN_REASON });
#endif
}

public void OnSignInSuccess(string googleId)
{
// use googleId
GetToken();
}

public void GooglePlusSignIn(){
#if UNITY_ANDROID && !UNITY_EDITOR
activityClass.SetStatic<string>("OnTokenReceivedCallback", "OnSignInSuccess");
activityClass.CallStatic("Start", new object[] { SIGN_IN_REASON });
#endif
}

public void OnTokenReceivedCallback(string accessToken)
{
PlayFabClientAPI.LoginWithGoogleAccount (new LoginWithGoogleAccountRequest () {
AccessToken = accessToken,
CreateAccount = true,
TitleId = NetworkInfo.PLAYFABTITLE_ID,
}, LoginCallback, ErrorCallback);
}

void OnDestroy(){
// cleanup activityClass
}
```
I just tested this workflow on my Nexus 5 running Marshmallow (6.0), it seems that there is an issue. I'm investigating this and I will update here asap.

I see that the device used is samsung GT-P5100 and Unity version 5.2.1f1 (the latter is probably . What Android version are you using, I'm guessing it's 5 or 5.1?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image
Hamza Lazaar answered

Also make sure you have this in your manifest:
<activity
android:name="com.ThugLeaf.GooglePlusForUnity.GooglePlusActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
</activity>

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image
Hamza Lazaar answered

Also make sure you have this line:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Adam Galla avatar image
Adam Galla answered

Thanks I try it. But I'm not sure where to put the 'meta' line. (sorry, but I don't often work with android...hehe).
I'm using 2.3.1 as minimum API level.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image
Hamza Lazaar answered

here's an example of where to put activity and meta-data xml tags/elements (inside <application></application>):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity android:name="com.ThugLeaf.GooglePlusForUnity.GooglePlusActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
</activity>
</application>
</manifest>

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image
Hamza Lazaar answered

I forgot to mention, this should go into:
{project_root_path}\Assets\Plugins\Android\AndroidManifest.xml

check if all other AndroidManifest.xml files inside your project do not include such entries. Unity will try merging all manifests to the main one (path given above), duplicate entries may cause build failure.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.