質問

Brefore user login, this code:

FB.Init(() =>
{
    FB.PublishInstall();
});

results in an error:

03-14 10:55:01.241: I/Unity(6662): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 54)
03-14 10:55:01.326: I/Unity(6662): Exception: java.lang.ExceptionInInitializerError
03-14 10:55:01.326: I/Unity(6662):   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at UnityEngine.AndroidJNISafe.CallStaticVoidMethod (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at UnityEngine.AndroidJavaObject._CallStatic (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at UnityEngine.AndroidJavaObject.CallStatic (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at Facebook.AndroidFacebook.CallFB (System.String method, System.String args) [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at Facebook.AndroidFacebook.PublishInstall (System.String appId, Facebook.FacebookDelegate callback) [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at FB.PublishInstall (Facebook.FacebookDelegate callback) [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at PublishInstallController.<PublishInstall>m__87 () [0x00000] in <filename unknown>:0 
03-14 10:55:01.326: I/Unity(6662):   at Facebook.AndroidFacebook.OnInitComplete

If a user is logged in before executing this code:

FB.PublishInstall();

everything goes well.

The documentation (Step 2: Add the Facebook SDK) says:

After installing the SDK, include the following code to be executed when your app is in the foreground. This will allow the app to ping back the install event to Facebook when the user opens up the app for the first time, and again in the future if there is a network error. Our client code will stop sending installs once it acquires a success code from the server, and our back-end will only count the install a single time if it receives multiple hits for the same device:

Question:

  1. Did I understand correctly that you can call FB.PublishInstall () before user authorization in facebook?
  2. Is there any possibility to fix this error?
役に立ちましたか?

解決

[EDIT]:

Me and a colleague found a workaround, at least for our case. We checked the logcat logs and we noticed an error with "AsyncTask". From what I could check, the Facebook Android SDK is trying to call publishInstall in another thread, and if this is the first call you make in your app using AsyncTask the crash occurs.

According to this post: http://grokbase.com/p/gg/android-developers/11ajf99wrs/possible-bug-in-asynctask the workaround might be to execute a dummy task through AsyncTask to "fool the system". This worked for us and the application is not crashing anymore. Hope it helps.

[/EDIT]

In case you're still searching for an answer:

Does FB.PublishInstall Require AuthToken?

  1. benp stated that publishInstall does not require an access token, so I'm guessing based on what he said that PublishInstall can be called before authorization.

  2. I'm having the same issue, but the crash occurs only on certain devices. Some devices just print the error message without a crash. This may be a Facebook SDK bug.

他のヒント

It seems, I found the solution of this problem, but for this purpose I had to change the source code of a plug-in of facebook SDK. In the FB.java (com.facebook.unity.FB) file:

@UnityCallable
    public static void PublishInstall(String params_str) 
    {
        final UnityMessage unityMessage = new UnityMessage("OnPublishInstallComplete");
        final UnityParams unity_params = UnityParams.parse(params_str);
        if (unity_params.hasString("callback_id")) {
            unityMessage.put("callback_id", unity_params.getString("callback_id"));
        }
        if (Looper.myLooper() == null)
        {
            Looper.prepare();
        }
        AppEventsLogger.activateApp(getUnityActivity().getApplicationContext());
        unityMessage.send();

    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top